Changes:
- Saves settings for compiler in the registry so if you run it again they are already pre-populated
- More error checking and notifications in general
- Run and RunWait moved to ShellExecute and ShellExecuteWait which solved some issues with Windows 7 and UAC for me
- Installs as a service on Windows 7 with UAC now
- Additional desktop shortcut to show the session ID for those that have installed InstantSupport as a service (in case they forgot the ID)
- Some other changes but that is enough for now I guess...
Only files changed are in the SRC directory in your %PROGRAM FILES%/ChunkVNC_3_3_1/SRC directory. Replace the Compiler.au3 and InstantSupport.au3 with the below code. Then run the 'Make Compiler.cmd' batch file in the %PROGRAM FILES%/ChunkVNC_3_3_1 folder to update everything. If like me you have windows UAC enabled you may need to copy the whole ChunkVNC_3_3_1 directory to your desktop in order to do the above and for it to work.
Compiler.au3:
Code: Select all
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=InstantSupport_Files\icon1.ico
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "Aut2Exe\Include\ButtonConstants.au3"
#include "Aut2Exe\Include\EditConstants.au3"
#include "Aut2Exe\Include\GUIConstantsEx.au3"
#include "Aut2Exe\Include\WindowsConstants.au3"
#include "Aut2Exe\Include\Constants.au3"
; Exit if the script hasn't been compiled.
If Not @Compiled Then
MsgBox(0, "ERROR", 'Script must be compiled before running!', 5)
Exit
EndIf
; Exit if an VNC server is running.
If ProcessExists( "winvnc.exe" ) Then
MsgBox(0, "ERROR", 'Compiling is not possible because a VNC server is running, please close the other VNC server and try again.', 5)
EndIf
$server = RegRead("HKEY_CURRENT_USER\Software\ChunkVNC", "Server")
if $server = "" Then $server = "example.repeater.com"
$ipaddress = RegRead("HKEY_CURRENT_USER\Software\ChunkVNC", "IPAddress")
if $ipaddress = "" Then $ipaddress = "192.168.1.1"
$viewport = RegRead("HKEY_CURRENT_USER\Software\ChunkVNC", "ViewerPort")
if $viewport = "" Then $viewport = "5901"
$servport = RegRead("HKEY_CURRENT_USER\Software\ChunkVNC", "ServerPort")
if $servport = "" Then $servport = "443"
$password = RegRead("HKEY_CURRENT_USER\Software\ChunkVNC", "Password")
if $password = "" Then $password = "password1"
; Create the GUI.
$Form1_1 = GUICreate("ChunkVNC Compiler", 434, 370, 192, 124)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("Repeater Address", 16, 8, 401, 137)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$InputWAN = GUICtrlCreateInput($server, 96, 48, 305, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$InputLAN = GUICtrlCreateInput($ipaddress, 96, 96, 305, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("WAN:", 32, 48, 49, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("LAN:", 32, 96, 43, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Repeater Ports", 16, 160, 401, 89)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$Label3 = GUICtrlCreateLabel("Viewer:", 32, 200, 63, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Server:", 232, 200, 61, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$InputViewerPort = GUICtrlCreateInput($viewport, 104, 200, 97, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
$InputServerPort = GUICtrlCreateInput($servport, 304, 200, 97, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("InstantSupport Password", 16, 264, 305, 89)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
$InputPassword = GUICtrlCreateInput($password, 32, 304, 273, 28)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
;GUICtrlSetLimit( $InputPassword, 8 )
$ButtonCompile = GUICtrlCreateButton("Compile!", 336, 272, 81, 81)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
; Main Loop.
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ButtonCompile
; Check the password.
$PlainTextPassword = GUICtrlRead( $InputPassword )
If $PlainTextPassword = "" or StringInStr( $PlainTextPassword, " " ) Then
MsgBox( 0, "Information", "The password cannot be blank or contain whitespace." )
ElseIf Stringlen( $PlainTextPassword ) < 9 Then
MsgBox( 0, "Information", "The password cannot be less than 9 characters." )
Else
; Automate the SecureVNC plugin to generate a password hash and store it in ultravnc.ini
RegWrite("HKEY_CURRENT_USER\Software\ChunkVNC", "Server", "REG_SZ", GUICtrlRead($InputWAN))
RegWrite("HKEY_CURRENT_USER\Software\ChunkVNC", "IPAddress", "REG_SZ", GUICtrlRead($InputLAN))
RegWrite("HKEY_CURRENT_USER\Software\ChunkVNC", "ViewerPort", "REG_SZ", GUICtrlRead($InputViewerPort))
RegWrite("HKEY_CURRENT_USER\Software\ChunkVNC", "ServerPort", "REG_SZ", GUICtrlRead($InputServerPort))
RegWrite("HKEY_CURRENT_USER\Software\ChunkVNC", "Password", "REG_SZ", $PlainTextPassword)
; Blank VNC passwords in ultravnc.ini so that the property page displays.
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "ultravnc", "passwd", "" )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "ultravnc", "passwd2", "" )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "admin", "DSMPluginConfig", "" )
; Configure SecureVNC with our password.
ShellExecute(@ScriptDir & "\SRC\InstantSupport_Files\winvnc.exe" )
If Not WinWait( " UltraVNC Server Property Page", "", 10) Then
Msgbox(4096, "Error", "UltraVNC application did not start: " & @ScriptDir & "\SRC\InstantSupport_Files\winvnc.exe")
ContinueLoop
EndIf
ControlClick(" UltraVNC Server Property Page", "Config.", "[CLASS:Button; INSTANCE:46]", "primary" )
If Not WinWait("SecureVNCPlugin Configuration", "", 10) Then
Msgbox(4096, "Error", "Did not switch to server property page")
ContinueLoop
EndIf
ControlSend( "SecureVNCPlugin Configuration", "", "[CLASS:Edit; INSTANCE:1]", $PlainTextPassword )
ControlSend( "SecureVNCPlugin Configuration", "", "[CLASS:Edit; INSTANCE:2]", $PlainTextPassword )
ControlClick("SecureVNCPlugin Configuration", "Close", "[CLASS:Button; INSTANCE:19]", "primary" )
ControlClick(" UltraVNC Server Property Page", "&Apply", "[CLASS:Button; INSTANCE:52]", "primary" )
; Kill the UltraVNC process.
Sleep( 500 ) ; Give old computers some time to write ultravnc.ini
ProcessClose( "winvnc.exe" )
; Put UltraVNC passwords back in ultravnc.ini (these arn't used it simply stops the server property page from popping up).
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "ultravnc", "passwd", "ac476d03f66b9e0300" )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "ultravnc", "passwd2", "8BF749ADC043135FED" )
; Setup source files with the repeaters address.
$RepeaterAddressWAN = GUICtrlRead( $InputWAN )
$RepeaterAddressLAN = GUICtrlRead( $InputLAN )
$ViewerPort = GUICtrlRead( $InputViewerPort )
$ServerPort = GUICtrlRead( $InputServerPort )
IniWrite( @ScriptDir & "\Viewer\Bin\chunkviewer.ini", "Repeater", "Address", $RepeaterAddressWAN )
IniWrite( @ScriptDir & "\Viewer\Bin\chunkviewer.ini", "Repeater", "AddressLAN", $RepeaterAddressLAN )
IniWrite( @ScriptDir & "\Viewer\Bin\chunkviewer.ini", "Repeater", "ViewerPort", $ViewerPort )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\instantsupport.ini", "Repeater", "Address", $RepeaterAddressWAN )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\instantsupport.ini", "Repeater", "AddressLAN", $RepeaterAddressLAN )
IniWrite( @ScriptDir & "\SRC\InstantSupport_Files\instantsupport.ini", "Repeater", "ServerPort", $ServerPort )
; Clean temp output directory.
DirRemove( @TempDir & "\ChunkVNC_Compiled", 1 )
; Compile InstantSupport.exe
DirCreate( @TempDir & "\ChunkVNC_Compiled" )
ShellExecuteWait( "SRC\Aut2Exe\Aut2Exe.exe", '/in SRC\InstantSupport.au3 /out "' & @TempDir & '\ChunkVNC_Compiled\InstantSupport.exe" /icon SRC\InstantSupport_Files\icon1.ico', @ScriptDir )
; Compile ChunkViewer.exe
ShellExecuteWait( "SRC\Aut2Exe\Aut2Exe.exe", "/in SRC\ChunkViewer.au3 /out Viewer\ChunkViewer.exe /icon SRC\InstantSupport_Files\icon1.ico", @ScriptDir )
; Check if SecureVNC was configured properly
$DSMPluginConfig = IniRead( @ScriptDir & "\SRC\InstantSupport_Files\ultravnc.ini", "admin", "DSMPluginConfig", $RepeaterAddressWAN )
If $DSMPluginConfig = "" Then
MsgBox( 0, "Information", "Compile Failed: SecureVNC plugin failed to configure. Please compile again." )
Exit
Else
If FileExists( @TempDir & "\ChunkVNC_Compiled\InstantSupport.exe" ) Then
FileMove( @ScriptDir & "\InstantSupport.exe", @TempDir & "\ChunkVNC_Compiled", 1 )
DirCopy( @ScriptDir & "\Viewer", @TempDir & "\ChunkVNC_Compiled\Viewer", 1 )
Run( "explorer.exe " & @TempDir & "\ChunkVNC_Compiled" )
Else
MsgBox( 0, "Information", "Compile Failed: InstantSupport.exe failed to compile. Please compile again." )
EndIf
EndIf
Sleep( 2000 )
MsgBox( 0, "Information", "If completed successfully you will find InstantSupport.exe and a Viewer directory. If you do not have these files try compiling again." )
Exit
EndIf
EndSwitch
WEnd
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
Code: Select all
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=InstantSupport_Files\icon1.ico
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Run_Obfuscator=Y
#Obfuscator_Parameters=/StripOnly
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; Disable the scripts ability to pause.
Break(0)
#include "Aut2Exe\Include\GUIConstantsEx.au3"
#include "Aut2Exe\Include\StaticConstants.au3"
#include "Aut2Exe\Include\WindowsConstants.au3"
#include "Aut2Exe\Include\ServiceControl.au3"
; Exit if the script hasn't been compiled
If Not @Compiled Then
MsgBox(0, "ERROR", 'Script must be compiled before running!', 5)
Exit
EndIf
; Language strings.
$str_Program_Title = "Instant Support"
$str_Button_InstallService = "Install As Service"
$str_Button_Exit = "Exit"
$str_MsgBox_Information = "Information"
$str_MsgBox_ExitInstantSupport = "Exit Instant Support?"
$str_MsgBox_ServiceInstallation = "Service Installation"
$str_MsgBox_Error = "Error"
$str_MsgBox_RemoveService = "Remove Service and Uninstall?"
$str_ServiceEnterAnIDNumber = "Enter an ID number:"
$str_ServiceInvalidID = "Invalid ID entered, service installation canceled."
$str_ServiceProxy = "Service installation not supported when using HTTP Proxy."
$str_ErrorInstallService = "Installing service requires administrator privileges."
$str_ErrorStopService = "Stopping VNC services requires administrator privileges."
$str_ErrorUnknownCommand = "Unknown command."
$str_ErrorRepeaterConnectionFailed = "Connection to the repeater was not possible."
$str_EndSupportSession = "Are you sure you want to end this support session?"
$str_CloseOtherVNCServers = "Another VNC server is running which must be stopped. Try to stop other VNC server?"
; Global Vars.
Global $ExtractFiles = True
Global $GenerateID = True
Global $LanMode = False
Global $IDNumber = 123456
Global $WorkingPath = @AppDataDir & "\InstantSupport_Temp_Files"
Global $ProxyEnabled = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable")
; Create unique working path if our default directory already exists. (Possible InstantSupport is already running)
If FileExists( @AppDataDir & "\InstantSupport_Temp_Files" ) Then
$WorkingPath = @AppDataDir & "\InstantSupport_Temp_Files_" & Random( 100000, 999999,1 )
EndIf
; Command line args.
If $cmdline[0] > 0 Then
Switch $cmdline[1]
Case "-installservice"
If IsAdmin() Then
InstallService()
Exit
Else
MsgBox( 0, $str_MsgBox_Error, $str_ErrorInstallService, 30 )
Exit
EndIf
Case "-removeservice"
If IsAdmin() Then
RemoveService()
Exit
Else
; Elevate to admin to remove.
ShellExecuteWait( @ScriptFullPath, "-removeservice", @ScriptDir, "runas")
Exit
EndIf
Case "-showid"
$IDNumber = IniRead(@ProgramFilesDir & "\InstantSupport\instantsupport.ini", "InstantSupport", "ID", "" )
msgbox(4096, "Instant Support", "Your Session ID is: " & $IDNumber & ". Tell your support technician this number when you wish them to connect up to the machine.")
Exit
Case "-stopservices"
If IsAdmin() Then
StopServices()
Exit
Else
MsgBox( 0, $str_MsgBox_Error, $str_ErrorStopService, 30 )
Exit
EndIf
Case Else
MsgBox( 0 , $str_MsgBox_Error, $str_ErrorUnknownCommand, 30 )
Exit
EndSwitch
EndIf
; Extract files.
If $ExtractFiles Then
DirCreate( $WorkingPath )
FileInstall( "InstantSupport_Files\instantsupport.ini", $WorkingPath & "\instantsupport.ini", 1 )
FileInstall( "InstantSupport_Files\logo.jpg", $WorkingPath & "\logo.jpg", 1 )
FileInstall( "InstantSupport_Files\SecureVNCPlugin.dsm", $WorkingPath & "\SecureVNCPlugin.dsm", 1 )
FileInstall( "InstantSupport_Files\ultravnc.ini", $WorkingPath & "\ultravnc.ini", 1 )
FileInstall( "InstantSupport_Files\winvnc.exe", $WorkingPath & "\InstantSupportVNC.exe", 1 )
FileInstall( "InstantSupport_Files\unblock.js", $WorkingPath & "\unblock.js", 1 )
; Unblock InstantSupport.exe to prevent "Windows Security" messages.
ShellExecuteWait($WorkingPath & "\unblock.js", "", @ScriptDir, "")
FileCopy( @ScriptDir & "\" & @ScriptName, $WorkingPath & "\InstantSupport.exe", 9 )
EndIf
; Close known VNC servers. --NEEDS WORK--
If ProcessExists( "InstantSupportVNC.exe" ) Or ProcessExists( "WinVNC.exe" ) Then
If MsgBox( 4, $str_Program_Title, $str_CloseOtherVNCServers ) = 6 Then
; Stop services if running.
If _ServiceRunning("", "uvnc_service") or _ServiceRunning("", "winvnc") Then
If IsAdmin() Then
ShellExecuteWait($WorkingPath & "\InstantSupport.exe", "-stopservices", @ScriptDir, "")
Else
ShellExecuteWait($WorkingPath & "\InstantSupport.exe", "-stopservices", @ScriptDir, "runas")
EndIf
Sleep(10000)
EndIf
; Kill user mode VNC servers.
KillVNC()
; Kill InstantSupport if running.
If WinExists( $str_Program_Title ) Then
WinClose( $str_Program_Title )
Sleep( 500 )
Send( "{ENTER}" ) ; Let the other InstantSupport process close normally so it can cleanup.
Sleep( 500 )
EndIf
Else
InstantSupportExit( True )
EndIf
EndIf
; Read server settings from instantsupport.ini.
$RepeaterAddress = IniRead( $WorkingPath & "\instantsupport.ini", "Repeater", "Address", "" )
$RepeaterAddressLAN = IniRead( $WorkingPath & "\instantsupport.ini", "Repeater", "AddressLAN", "" )
$RepeaterServerPort = IniRead( $WorkingPath & "\instantsupport.ini", "Repeater", "ServerPort", "" )
; Generate a random ID Number between 200,000 and 999,999 or read the installed ID number.
If $GenerateID Then
$LowerLimit = 200000
$UpperLimit = 999999
$IDNumber = Random( $LowerLimit,$UpperLimit,1 )
Else
$IDNumber = IniRead( $WorkingPath & "\instantsupport.ini", "InstantSupport", "ID", "" )
EndIf
; Create the GUI.
$InstantSupport = GUICreate( $str_Program_Title, 450, 200, -1, -1, BitOR( $WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS,$WS_MINIMIZEBOX ) )
GUISetBkColor( 0xFFFFFF )
$Label2 = GUICtrlCreateLabel( $IDNumber, 0, 100, 450, 100, $SS_CENTER )
GUICtrlSetFont( -1, 50, 800, 0, "Arial Black" )
$Pic1 = GUICtrlCreatePic( $WorkingPath & "\logo.jpg", 0, 0, 450, 90, BitOR( $SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS ) )
GUISetState( @SW_SHOW )
WinSetOnTop( $str_Program_Title, "",1)
; Check to see if the repeater exists unless there is a proxy.
If $ProxyEnabled = False Then
TCPStartUp()
; Test WAN address first.
$socket = TCPConnect( TCPNameToIP( $RepeaterAddress ), $RepeaterServerPort )
If $socket = -1 Then $LanMode = True
; Test LAN Address because WAN failed.
If $LanMode = True Then
$socket = TCPConnect( TCPNameToIP( $RepeaterAddressLAN ), $RepeaterServerPort )
If $socket = -1 Then
; No connections possible, exit.
WinSetOnTop( $str_Program_Title, "",0 )
MsgBox( 48, $str_MsgBox_Error, $str_ErrorRepeaterConnectionFailed, 10 )
InstantSupportExit( True )
EndIf
EndIf
TCPShutdown()
EndIf
; Start the VNC server and make a reverse connection to the repeater.
If $LanMode = True Then
ShellExecute( $WorkingPath & "\InstantSupportVNC.exe", "-httpproxy -autoreconnect ID:" & $IDNumber & " -connect " & $RepeaterAddressLAN & ":" & $RepeaterServerPort & " -run" )
Else
ShellExecute( $WorkingPath & "\InstantSupportVNC.exe", "-httpproxy -autoreconnect ID:" & $IDNumber & " -connect " & $RepeaterAddress & ":" & $RepeaterServerPort & " -run" )
EndIf
; Create the tray icon. Default tray menu items (Script Paused/Exit) will not be shown.
Opt( "TrayMenuMode", 1 )
$InstallItem = TrayCreateItem( $str_Button_InstallService )
$ExitItem = TrayCreateItem( $str_Button_Exit )
; Enable the scripts ability to pause. (otherwise tray menu is disabled)
Break(1)
; Main loop.
While 1
; Close any windows firewall messages that popup. The windows firewall doesn't block outgoing connections anyways. ----Does the OS language change this?----
If WinExists( "Windows Security Alert" ) Then WinClose( "Windows Security Alert" )
; If UltraVNC can't connect to the repeater then exit.
If WinExists( "Initiate Connection" ) Then
; Stop the VNC server
ProcessClose( "InstantSupportVNC.exe" )
ProcessWaitClose( "InstantSupportVNC.exe" )
WinSetOnTop( $str_Program_Title, "",0 )
MsgBox( 48, $str_MsgBox_Error, $str_ErrorRepeaterConnectionFailed )
InstantSupportExit( True )
EndIf
; Check for form events.
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
WinSetOnTop( $str_Program_Title, "",0 )
If MsgBox( 4, $str_Program_Title, $str_EndSupportSession ) = 6 Then
InstantSupportExit( True )
EndIf
EndSwitch
; Tray events.
$nMsg = TrayGetMsg()
Switch $nMsg
Case $InstallItem
; Service installation unavailable if using an HTTP Proxy (UltraVNC limitation).
If $ProxyEnabled = True Then
WinSetOnTop( $str_Program_Title, "",0 )
MsgBox( 48, $str_MsgBox_Error, $str_ServiceProxy, 10 )
Else
; Choose ID for service installation.
WinSetOnTop( $str_Program_Title, "",0 )
$IDNumber = InputBox( $str_MsgBox_ServiceInstallation, $str_ServiceEnterAnIDNumber, $IDNumber ) +0
If IsNumber($IDNumber) and $IDNumber > 200000 and $IDNumber < 999999 Then
; Configure ultravnc.ini
If $LanMode = True Then
IniWrite( $WorkingPath & "\ultravnc.ini", "admin", "service_commandline", '-autoreconnect ID:' & $IDNumber & ' -connect ' & $RepeaterAddressLAN & ":" & $RepeaterServerPort )
Else
IniWrite( $WorkingPath & "\ultravnc.ini", "admin", "service_commandline", '-autoreconnect ID:' & $IDNumber & ' -connect ' & $RepeaterAddress & ":" & $RepeaterServerPort )
EndIf
; Configure instantsupport.ini
IniWrite( $WorkingPath & "\instantsupport.ini", "InstantSupport", "ID", $IDNumber )
; Kill the VNC server
If KillVNC() = 1 Then ContinueLoop
If IsAdmin() Then
ShellExecute($WorkingPath & "\InstantSupport.exe", "-installservice", @ScriptDir, "")
Else
ShellExecute($WorkingPath & "\InstantSupport.exe", "-installservice", @ScriptDir, "runas")
EndIf
If @error > 0 Then
msgbox(4096, "Error", "Unable to complete the instant support service installation. Try copying instantsupport.exe to your desktop and running it from there: " & IsAdmin() & " - " & $WorkingPath & "\InstantSupport.exe -installservice")
EndIf
InstantSupportExit( True )
Else
WinSetOnTop( $str_Program_Title, "",0 )
MsgBox( 0, $str_MsgBox_Information, $str_ServiceInvalidID )
EndIf
EndIf
Case $ExitItem
WinSetOnTop( $str_Program_Title, "",0 )
If MsgBox( 4, $str_Program_Title, $str_EndSupportSession ) = 6 Then
InstantSupportExit( True )
EndIf
EndSwitch
WEnd
Func InstallService()
; Copy files.
$result = FileCopy( @ScriptDir & "\*.*", @ProgramFilesDir & "\InstantSupport\", 9 )
If $result = 0 or FileExists(@ProgramFilesDir & "\InstantSupport\InstantSupport.exe") = 0 Then
Msgbox(4096, "Error copying files", "We were unable to install InstantSupport as a service. This is usually due to access restrictions, try re-running Instant Support by right clicking on it's icon and selecting 'Run as Administrator'")
Return
EndIf
; Create uninstall link on All Users desktop.
FileCreateShortcut( @ProgramFilesDir & '\InstantSupport\InstantSupport.exe', @DesktopCommonDir & '\Uninstall Instant Support.lnk', "", "-removeservice" )
FileCreateShortcut( @ProgramFilesDir & '\InstantSupport\InstantSupport.exe', @DesktopCommonDir & '\View Instant Support ID.lnk', "", "-showid" )
; Install VNC Service.
ShellExecute( @ProgramFilesDir & "\InstantSupport\InstantSupportVNC.exe", "-install" )
EndFunc
Func RemoveService()
WinSetOnTop( $str_Program_Title, "",0 )
If MsgBox( 4, $str_Program_Title, $str_MsgBox_RemoveService ) = 6 Then
; Remove Uninstaller
FileDelete( @DesktopCommonDir & '\Uninstall Instant Support.lnk"' )
FileDelete( @DesktopCommonDir & '\View Instant Support ID.lnk"' )
; Remove VNC Service.
ShellExecute( @ProgramFilesDir & "\InstantSupport\InstantSupportVNC.exe", "-uninstall" )
; Run installer after the server exits.
If ProcessWaitClose( "InstantSupportVNC.exe", 15) = 0 Then
Msgbox(4096, "Error", "Instant support VNC is still running")
Return 1
EndIf
; Remove the InstantSupport Service.
DirRemove(@ProgramFilesDir & "\InstantSupport", 1)
;_DeleteSelf( @ProgramFilesDir & "\InstantSupport", 15 )
EndIf
EndFunc
Func _DeleteSelf( $Path, $iDelay = 5 )
; Not used anymore (replaced by process detection and dirremove)
Local $sCmdFile
FileDelete( @TempDir & "\scratch.bat" )
$sCmdFile = 'PING -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
& 'DEL /F /Q "' & $Path & '\InstantSupportVNC.exe"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\InstantSupport.exe"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\SecureVNCPlugin.dsm"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\ultravnc.ini"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\instantsupport.ini"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\logo.jpg"' & @CRLF _
& 'DEL /F /Q "' & $Path & '\unblock.js"' & @CRLF _
& 'RMDIR "' & $Path & '"' & @CRLF _
& 'DEL "' & @TempDir & '\scratch.bat"'
FileWrite( @TempDir & "\scratch.bat", $sCmdFile )
Run( @TempDir & "\scratch.bat", @TempDir, @SW_HIDE )
EndFunc
Func InstantSupportExit( $DeleteFiles = False )
; Kill the VNC server
KillVNC()
; Remove temp files.
If $DeleteFiles = True Then DirRemove($WorkingPath, 1) ;_DeleteSelf( $WorkingPath, 5)
Exit
EndFunc
Func KillVNC()
ShellExecuteWait($WorkingPath & "\InstantSupportVNC.exe", "-kill")
If @error > 0 then
Msgbox(4096, "Error", "Instant support VNC server did not close when called with -kill argument: " & $WorkingPath & "\InstantSupportVNC.exe -kill")
return 1
EndIf
; Run installer after the server exits.
If ProcessWaitClose( "InstantSupportVNC.exe", 15) = 0 Then
Msgbox(4096, "Error", "Instant support VNC is still running")
Return 1
EndIf
return 0
EndFunc
Func StopServices()
_StopService("", "uvnc_service")
_StopService("", "winvnc")
EndFunc