sugi Posted May 11, 2004 Posted May 11, 2004 I've written a script to remotely install VNC on the computer of a user and uninstall after the connection has terminated (using a lot of extra utilities).It consists of two parts. the first: vncvwr.au3 is run on the computer you're using yourself and asks which computer you want to install VNC to.The second script, vncsrv.au3 does the actual job: Asking the user if it's ok to remote control his/her computer, importing some registry settings and then run the vnc server.The script will need some fine tuning before you'll be able to use it, but maybe it gives you a good starting point to create your own vnc installer for your network. This whole thing was written for a company environment, so if you're not within a domain you might have to logon to the other computer first (e.g. accessing \\remotecomputer\admin$ and entering your password). The script tries to check if you've got admin rights on the remote computer. You'll also need all the external commands I used. See the links below the scripts.The messages are in german but I think by checking the source you can figure out what a specific message means. If not, contact me, I'll translate it to english then.First vncsrv.au3:expandcollapse popupAutoItSetOption("TrayIconHide",1) Break(0) Dim $ClientName, $TMP, $IniFile, $X $TMP = @SystemDir & "\VNC" If $CmdLine[0] < 1 Then Exit(1) EndIf $ForceConnect = 0 $ClientName = $CmdLine[1] If $ClientName = '-force' Then $ForceConnect = 1 $ClientName = $CmdLine[2] EndIf If not $ForceConnect Then $X = MsgBox(4 + 262144, "Fernsteuerung", "Die unten angegebene Person möchte diesen Computer fernsteuern. Möchten Sie dies erlauben?" & @CR & "Anfrage von: " & $ClientName) If $X = 7 Then MsgBox(0, "Fernsteuerung", "Die Fernsteuerung wurde abgebrochen") Exit(1) EndIf EndIf DirCreate($TMP) FileInstall("..\source\othread2.dll", $TMP & "\othread2.dll") FileInstall("..\source\vnchooks.dll", $TMP & "\vnchooks.dll") FileInstall("..\source\winvnc.exe", $TMP & "\winvnc.exe") FileInstall("..\source\settings.reg", $TMP & "\settings.reg", 1) RunWait("regedit /s " & $TMP & "\settings.reg") Run('"' & $TMP & '\winvnc.exe"') ProcessWait("winvnc.exe") While ProcessExists("winvnc.exe") Sleep(1000) WEnd RegDelete("HKEY_CURRENT_USER\Software\ORL") RegDelete("HKEY_LOCAL_MACHINE\Software\ORL") FileDelete($TMP & "\othread2.dll") FileDelete($TMP & "\vnchooks.dll") FileDelete($TMP & "\winvnc.exe") DirRemove($TMP,1) MsgBox(0, "Fernsteuerung", "Fernsteuerung wurde beendet.")Here's vncvwr.au3:expandcollapse popupAutoItSetOption("TrayIconHide",1) Break(0) $MyName = RegRead("HKEY_CURRENT_USER\Software\sugi\VNCVWR", "MyName") If @error Then $MyName = InputBox("Fernsteuerung", "Name?", EnvGet("USERNAME")) EndIf RegWrite("HKEY_CURRENT_USER\Software\sugi\VNCVWR", "MyName", "REG_SZ", $MyName) If $CmdLine[0] = 0 Then $RemoteComputer = InputBox("Fernsteuerung", "Welchen Computer fernsteuern?", RegRead("HKEY_CURRENT_USER\Software\sugi\VNCVWR", "LastComputer")) If @error Then Exit(1) EndIf RegWrite("HKEY_CURRENT_USER\Software\sugi\VNCVWR", "LastComputer", "REG_SZ", $RemoteComputer) Else $RemoteComputer = $CmdLine[1] EndIf $Confirm = MsgBox(4, "Fernsteuerung", "Bestätigung des Users anfordern?") ProgressOn("Installiere VNC Server auf " & $RemoteComputer, "Extrahiere Dateien...") FileInstall("..\source\vncviewer.exe", @TempDir & "\vncviewer.exe") FileInstall("..\source\psexec.exe", @TempDir & "\psexec.exe") FileInstall("..\source\pskill.exe", @TempDir & "\pskill.exe") FileInstall("..\source\nc.exe", @TempDir & "\nc.exe") FileInstall("vncsrv.exe", @TempDir & "\vncsrv.exe", 1) ProgressSet(33, "Kopiere und starte VNC Server....") DriveSpaceFree('\\' & $RemoteComputer & '\admin$') If @error Then ProgressOff() MsgBox(4096, "Fernsteuerung", 'Keine administrativen Berechtigungen auf ' & $RemoteComputer) Exit(1) EndIf If $Confirm = 7 Then Run(@TempDir & "\psexec.exe \\" & $RemoteComputer & " -i -c -f -s " & @TempDir & '\vncsrv.exe -force "' & $MyName & '"' , "", @SW_HIDE) Else Run(@TempDir & "\psexec.exe \\" & $RemoteComputer & " -i -c -f -s " & @TempDir & '\vncsrv.exe "' & $MyName & '"' , "", @SW_HIDE) EndIf ProcessWait("psexec.exe") ProgressSet(66, "Warte bis der VNC Server gestartet ist...") $i = 0 While $i < 120 If RunWait(@TempDir & '\nc.exe -z ' & $RemoteComputer & ' 5900', "", @SW_HIDE) = 0 Then ExitLoop EndIf If not ProcessExists("psexec.exe") Then ExitLoop EndIf Sleep(500) WEnd ProgressOff() If RunWait(@TempDir & '\nc.exe -z ' & $RemoteComputer & ' 5900', "", @SW_HIDE) = 0 Then RunWait(@TempDir & "\vncviewer.exe " & $RemoteComputer) RunWait(@TempDir & '\pskill.exe \\' & $RemoteComputer & ' winvnc.exe', "", @SW_HIDE) Else MsgBox(4096, "Fernsteuerung fehlgeschlagen", "Der Remote-Computer hat innerhalb der Wartezeit keine Verbindungen akzeptiert.") EndIf FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\nc.exe") FileDelete(@TempDir & "\vncsrv.exe")Here are the links to the external utilities:nc.exe (Netcat): http://www.atstake.com/research/tools/network_utilities/psexec and pskill: http://www.sysinternals.com/ntw2k/freeware/pstools.shtmlAll other files belong to VNC: http://www.realvnc.org/download.htmlThe settings.reg should be created by yourself. When installing the VNCserver on you computer, you'll be asked for a password and other things. Just configure it, then use regedit to export the key HKEY_LOCAL_MACHINE\Software\ORL to settings.reg and compile vncsrv.au3, then vncvwr.au3 (last one is optional).
DJ VenGenCe Posted December 30, 2005 Posted December 30, 2005 I am going to try to update this Script so it works with current standards. Cannot located 0thread2.dll anymore. Doesn't appear to install.
marcovich Posted March 3, 2006 Posted March 3, 2006 I am going to try to update this Script so it works with current standards. Cannot located 0thread2.dll anymore. Doesn't appear to install.Have you any new version? It works for TightVNC?
DJ VenGenCe Posted March 7, 2006 Posted March 7, 2006 Yes, going through the code, and will post soon. Works with latest beta of TightVNC
DJ VenGenCe Posted March 7, 2006 Posted March 7, 2006 (edited) ** Note ** Requires software from Sysinternals - SysInternals Website1. Download PsTools v2.3 (Under Networking)2. Extract to Any Directory3. Copy and these two programs (Service Center.au3 & Serve.au3)4. Compile Service Center.au3 (Optional)5. Compile serve.au3 (Mandatory)6. Run Service Center.au3 a. Type Remote Computer Name (LAN) b. If it does not work, try again (Sometiems get Failed Connections) c. I am not sure, but I beleive you have to have the proper privelages to use)Suggestions Are Welcome.Service Center.au3expandcollapse popup#NoTrayIcon;Disables Local Tray Icon $compname = INPUTBOX("Remote Control", "Remote Control Address", "", "", -1, 120) FileInstall("vncviewer.exe", @TempDir & "\vncviewer.exe") FileInstall("vnchooks.dll", @TempDir & "\vnchooks.dll") FileInstall("pskill.exe", @TempDir & "\pskill.exe") FileInstall("psexec.exe", @TempDir & "\psexec.exe") FileInstall("serve.exe", @TempDir & "\serve.exe") Run(@TempDir & "\psexec.exe \\" & $compname & " -i -c -f -s serve.exe -force " & $compname & '"' , "", @SW_HIDE) ProcessWait("psexec.exe") $i = 0 While $i < 99 If not ProcessExists("psexec.exe") Then MsgBox(0, "PSEXEC.EXE Does Not Exist", "PSEXEC.EXE Does not Exist") ExitLoop Else Sleep(500) $i = $i + 5 EndIf Wend RunWait(@TempDir & "\vncviewer.exe " & $compname) RunWait(@TempDir & '\pskill.exe \\' & $compname & ' winvnc.exe', "", @SW_HIDE) #cs Clean up - Remove The Files #ce ProgressOn("Disconnecting", "Decrements every second", "100 percent") Sleep(500) ProgressSet(10 , "Deleting Files", "Complete") FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\vnchooks.dll") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\serve.exe") Sleep(100) ProgressSet(100 , "", "Complete") Sleep(1000) ProgressOff()Serve.au3expandcollapse popup#NoTrayIcon;Shut Off Tray Icon $compname = @ComputerName;Set Variable $compname to Computer name (Server) RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ORL\WinVNC3", "AuthRequired", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ORL\WinVNC3", "DisableTrayIcon", "REG_DWORD", "1") FileInstall("vncviewer.exe", @TempDir & "\vncviewer.exe") FileInstall("psexec.exe", @TempDir & "\psexec.exe") FileInstall("pskill.exe", @TempDir & "\pskill.exe") FileInstall("vnc.ini", @TempDir & "\vncsrv.exe", 1) If @error Then MsgBox(4096, "Error", 'Could Not Connect to Host: ' & $RemoteComputer) RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\ORL") RegDelete("HKEY_CURRENT_USER\SOFTWARE\ORL") DirRemove("C:\PROGRA~1\WVNC",1) FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\vncsrv.exe") Exit(1) Else FileInstall("vnchooks.dll", @TempDir & "\vnchooks.dll") FileInstall("winVNC.exe", @TempDir & "\winVNC.exe") Run(@TempDir & "\WinVNC.exe") While ProcessExists("winvnc.exe") WEnd Sleep(500) RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\ORL") RegDelete("HKEY_CURRENT_USER\SOFTWARE\ORL") DirRemove("C:\PROGRA~1\WVNC",1) FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\vncsrv.exe") $PID = ProcessExists("winvnc.exe"); Will return the PID or 0 if the process isn't found. MsgBox(0, $PID, $PID) EndIf** Note 2 ** I am working on Trimming the fat out of this code.. some things may be unnecessary.I am going to be working on Remote Internet Compatibility, but that it totally in the works!As I said, Suggestions are welcome and code improvements are definitly appreciated.3/7/06 @ 1:15 PM EST - Added "While & If" statments to slow down the attempt to connect and wait for the remote process to spawnThanks Edited March 7, 2006 by DJ VenGenCe
marcovich Posted March 8, 2006 Posted March 8, 2006 ** Note ** Requires software from Sysinternals - SysInternals Website 1. Download PsTools v2.3 (Under Networking) 2. Extract to Any Directory 3. Copy and these two programs (Service Center.au3 & Serve.au3) 4. Compile Service Center.au3 (Optional) 5. Compile serve.au3 (Mandatory) 6. Run Service Center.au3 a. Type Remote Computer Name (LAN) b. If it does not work, try again (Sometiems get Failed Connections) c. I am not sure, but I beleive you have to have the proper privelages to use) Suggestions Are Welcome. Service Center.au3 expandcollapse popup#NoTrayIcon;Disables Local Tray Icon $compname = INPUTBOX("Remote Control", "Remote Control Address", "", "", -1, 120) FileInstall("vncviewer.exe", @TempDir & "\vncviewer.exe") FileInstall("vnchooks.dll", @TempDir & "\vnchooks.dll") FileInstall("pskill.exe", @TempDir & "\pskill.exe") FileInstall("psexec.exe", @TempDir & "\psexec.exe") FileInstall("serve.exe", @TempDir & "\serve.exe") Run(@TempDir & "\psexec.exe \\" & $compname & " -i -c -f -s serve.exe -force " & $compname & '"' , "", @SW_HIDE) ProcessWait("psexec.exe") $i = 0 While $i < 99 If not ProcessExists("psexec.exe") Then MsgBox(0, "PSEXEC.EXE Does Not Exist", "PSEXEC.EXE Does not Exist") ExitLoop Else Sleep(500) $i = $i + 5 EndIf Wend RunWait(@TempDir & "\vncviewer.exe " & $compname) RunWait(@TempDir & '\pskill.exe \\' & $compname & ' winvnc.exe', "", @SW_HIDE) #cs Clean up - Remove The Files #ce ProgressOn("Disconnecting", "Decrements every second", "100 percent") Sleep(500) ProgressSet(10 , "Deleting Files", "Complete") FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\vnchooks.dll") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\serve.exe") Sleep(100) ProgressSet(100 , "", "Complete") Sleep(1000) ProgressOff() Serve.au3 expandcollapse popup#NoTrayIcon;Shut Off Tray Icon $compname = @ComputerName;Set Variable $compname to Computer name (Server) RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ORL\WinVNC3", "AuthRequired", "REG_DWORD", "0") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\ORL\WinVNC3", "DisableTrayIcon", "REG_DWORD", "1") FileInstall("vncviewer.exe", @TempDir & "\vncviewer.exe") FileInstall("psexec.exe", @TempDir & "\psexec.exe") FileInstall("pskill.exe", @TempDir & "\pskill.exe") FileInstall("vnc.ini", @TempDir & "\vncsrv.exe", 1) If @error Then MsgBox(4096, "Error", 'Could Not Connect to Host: ' & $RemoteComputer) RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\ORL") RegDelete("HKEY_CURRENT_USER\SOFTWARE\ORL") DirRemove("C:\PROGRA~1\WVNC",1) FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\vncsrv.exe") Exit(1) Else FileInstall("vnchooks.dll", @TempDir & "\vnchooks.dll") FileInstall("winVNC.exe", @TempDir & "\winVNC.exe") Run(@TempDir & "\WinVNC.exe") While ProcessExists("winvnc.exe") WEnd Sleep(500) RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\ORL") RegDelete("HKEY_CURRENT_USER\SOFTWARE\ORL") DirRemove("C:\PROGRA~1\WVNC",1) FileDelete(@TempDir & "\vncviewer.exe") FileDelete(@TempDir & "\psexec.exe") FileDelete(@TempDir & "\pskill.exe") FileDelete(@TempDir & "\vncsrv.exe") $PID = ProcessExists("winvnc.exe"); Will return the PID or 0 if the process isn't found. MsgBox(0, $PID, $PID) EndIf ** Note 2 ** I am working on Trimming the fat out of this code.. some things may be unnecessary. I am going to be working on Remote Internet Compatibility, but that it totally in the works! As I said, Suggestions are welcome and code improvements are definitly appreciated. 3/7/06 @ 1:15 PM EST - Added "While & If" statments to slow down the attempt to connect and wait for the remote process to spawn Thanks I did work yesterday with your code and I get working it in my LAN. I think it is a good script but using PSTOOLS is difficult, because I had to adjust the server in each case (two tested) in a try and error approach. May be the problem is my ignorance to make a good configuration, but I think that a remote executing process must be mostly self-installed. In any case what I really need is the Remote Internet version, so I will be looking for your script. Thanks a lot
pietrog Posted March 21, 2006 Posted March 21, 2006 This script will install UltraVNC on a remote computer. You need to have the following files in your @ScriptDir vnchooks.dll, winVNC.exe, and vncviewer.exe. The script uses WMI to install the service on the remote PC and to determine the Windows Directory. After the viewer is closed, the script will clean up after itself on the local and remote PC. expandcollapse popup$compname = INPUTBOX("Remote Control", "Remote Control Address", "", "", -1, 120) Ping($compname) If @error Then MsgBox(0,"error", "PC not alive") Exit EndIf RegWrite("\\" & $compname & "\HKLM\SOFTWARE\ORL\WinVNC3", "AuthRequired", "REG_DWORD", "1") RegWrite("\\" & $compname & "\HKLM\SOFTWARE\ORL\WinVNC3", "DisableTrayIcon", "REG_DWORD", "1") RegWrite("\\" & $compname & "\HKLM\SOFTWARE\ORL\WinVNC3\Default", "Password", "REG_BINARY", "DBD83CFD727A1458") FileInstall("vnchooks.dll", "\\" & $compname & "\admin$\temp\vnchooks.dll") FileInstall("winVNC.exe", "\\" & $compname & "\admin$\temp\winVNC.exe") FileInstall("vncviewer.exe", @ScriptDir & "\viewer.exe") $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $compname & "\root\cimv2") $colItems = $objWMIService.ExecQuery("Select * From Win32_OperatingSystem") For $objItem in $colItems $windir=$objItem.WindowsDirectory Next $objNewService = $objWMIService.Get ("Win32_Service") $errReturn = $objNewService.Create ("VNC", "VNC", $windir & "\temp\winVNC.exe -service", "16", "0", "Manual", "1") $colListOfServices = $objWMIService.ExecQuery ("Select * from Win32_Service Where Name = 'VNC'") For $objNewService in $colListOfServices $objNewService.StartService() Next Sleep(1000) RunWait(@ScriptDir & "\viewer.exe -connect " & $compname & " -password password -nostatus") For $objNewService in $colListOfServices $objNewService.StopService() $objNewService.Delete() Next Sleep(1000) FileDelete("\\" & $compname & "\admin$\temp\vnchooks.dll") FileDelete("\\" & $compname & "\admin$\temp\winVNC.exe") FileDelete(@ScriptDir & "\viewer.exe") RegDelete("\\" & $compname & "\HKLM\SOFTWARE\UltraVNC") RegDelete("\\" & $compname & "\HKCU\SOFTWARE\ORL") RegDelete("HKCU\SOFTWARE\ORL")
slightly_abnormal Posted March 21, 2006 Posted March 21, 2006 (edited) would this work with ultravcn winviewer?, the version i have doesn't require installion btw.. Edited March 21, 2006 by slightly_abnormal
pietrog Posted March 22, 2006 Posted March 22, 2006 I've tested it with UltraVNC. The script creates the VNC service on the remote pc, starts the vncviewer program locally, and establishes a connection between the two. I'm in a domain environment with admin rights on both pcs.
powaking Posted March 23, 2006 Posted March 23, 2006 I've tested it with UltraVNC. The script creates the VNC service on the remote pc, starts the vncviewer program locally, and establishes a connection between the two. I'm in a domain environment with admin rights on both pcs.With RealVNC you can specify the -SecurityTypes=none so that no password is required but also include -queryconnect=1 so that the end user is prompted to either accept or reject the connection.I have it this way with my RC tool. A lot easier than importing registry entries and then removing registry entries as well.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now