#include <Constants.au3>
#include <Inet.au3>  ; um die inet ip abfragen zu können
Global $kill_vnc
Global $command = "netsh firewall"
Global $internet_ip
Global $hotline= "xxxxxxxxxxxxxxxxxxxxxxxx." & @CRLF & @CRLF & "xxxxxxxxxxxxxxx  " & @CRLF & @CRLF & "Ihre IP Adresse ist " 
;----------------  check ob vnc verzeichnis da und dateien drin sind
if FileExists('c:\orgs\vnc\winvnc4.exe') = 0 then
	DirCreate('c:\orgs\vnc')
	fileinstall('c:\orgs\vnc\winvnc4.exe','c:\orgs\vnc\winvnc4.exe')
	fileinstall('c:\orgs\vnc\logmessages.dll','c:\orgs\vnc\logmessages.dll')
	fileinstall('c:\orgs\vnc\wm_hooks.dll','c:\orgs\vnc\wm_hooks.dll')
Endif
;------------------------- teste ob online --------------------------------
if ping('www.google.com', 700) =0 Then
	MsgBox(16, 'FEHLER', 'Es besteht keine Verbindung zum Internet',15)
	exit
EndIf
;------------------------ Windows Firewall Ports freischalten und VNC starten
Run(@comspec & ' /c ' & ' netsh firewall set port 54543 enable',"",$OPT_ERRORSILENT)
Run(@comspec & ' /c ' & ' netsh firewall set allowedprogram "C:\orgs\VNC\winvnc4.exe" "Fernwartung" ENABLE',"",$OPT_ERRORSILENT)
Run(@comspec & ' /c ' & ' C:\orgs\VNC\winvnc4.exe portnumber=54543 HTTPPortNumber=54542 Queryconnect=1 SecurityTypes=none hosts=+ RemoveWallpaper=true RemovePattern=true DisableEffects=true',"",$OPT_ERRORSILENT)
;------------------------ check ob VNC läuft und hole IP Adresse
$internet_ip=_GetIP()
if ProcessExists( 'winvnc4.exe' ) Then
	MsgBox(64,"Fernwartung gestartet", $hotline & $internet_ip )
Else
	MsgBox(16,"FEHLER", " ACHTUNG das starten der Fernwartung ist fehlgeschlagen!",15)
EndIf	
$kill_vnc=MsgBox(16, 'Fernwartung', 'Mit OK wird die Fernwartung beendet und die Ports geschlossen!' & @CRLF & @CRLF & 'JETZT  BEENDEN ? ')
if $kill_vnc=1 then ProcessClose( 'winvnc4.exe')

Run(@comspec & ' /c ' & ' netsh firewall delete portopening TCP 54543',"",$OPT_ERRORSILENT)
Run(@comspec & ' /c ' & ' netsh firewall set allowedprogram "C:\orgs\VNC\winvnc4.exe" "Fernwartung" DISABLE',"",$OPT_ERRORSILENT)
MsgBox(64,"Fernwartung", " Vielen Dank  -  Sitzung beendet! ",15)