Dim UltraVNCVersion '### Increment version here as necessary ### UltraVNCVersion = "1.2.1.2" '### Additional Uninstall strings may need to be added to function uninstallNewPath() Set WshShell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") Const ForAppending = 8 Const ForReading = 1 Const CreateIfNotExist = True Const OpenAsASCII = 0 Set wmi = GetObject("winmgmts:\\.\root\cimv2") VNCRegKey = "HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion" Dim InstallInProgress Dim SearchInstallInProgress SearchInstallInProgress = "MainEngineThread is returning 1618" Dim MSIUninstallLog MSIUninstallLog = "C:\Temp\UltraVNCUninstallLog.txt" Dim MSIInstallLog MSIInstallLog = "C:\Temp\UltraVNCInstallLog.txt" Dim LoggyLog Dim oLogText LoggyLog = "C:\Temp\uvncinstall.txt" Dim Executable Executable = "\\Server\apps\Public\General\UltraVNC\UltraVnc_X64.msi" If fso.FileExists(LoggyLog) then fso.DeleteFile LoggyLog End If If fso.FileExists(MSIUninstallLog) then fso.DeleteFile MSIUninstallLog End If If fso.FileExists(MSIInstallLog) then fso.DeleteFile MSIInstallLog End If Set oLogText = fso.OpenTextFile(LoggyLog,ForAppending,CreateIfNotExist,OpenAsASCII) 'Check and see if this has run before If readfromRegistry("HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion", "") = UltraVNCVersion then wscript.echo "Version " & readfromRegistry("HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion", "") & " detected" wscript.echo "VNC is already at the latest version" oLogText.WriteLine Now & " - Version " & readfromRegistry("HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion", "") & " detected" oLogText.WriteLine Now & " - VNC is already at the latest version" 'do nothing else 'If not latest version, continue below wscript.echo "Version " & readfromRegistry("HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion", "") & " detected" oLogText.WriteLine Now & " - Version " & readfromRegistry("HKLM\Software\Company\PCSetup\ultravnc\InstalledVersion", "") & " detected" wscript.echo "Upgrading to " & UltraVNCVersion oLogText.WriteLine Now & " - Upgrading to " & UltraVNCVersion 'Run uninstall strings for previous versions If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe") then Set svcs = wmi.ExecQuery("Select * from Win32_Service where Name = 'uvnc_service'") If svcs.Count > 0 Then StopService ".", "uvnc_service", True wscript.echo "Stopped uvnc service" oLogText.WriteLine Now & " - Stopped 1.1.x.x or 1.2.x.x uvnc service" wscript.sleep 3000 End If wscript.echo "Uninstalling Previous Versions" oLogText.WriteLine Now & " - Uninstalling Previous Versions" 'Loop through the uninstall in case MSIexec is already running at startup do until UninstallEnded = 1 UninstallEnded = 1 'Attempt uninstall from new path sources uninstallNewPath() wscript.echo "Ran uninstall scripts" oLogText.WriteLine Now & " - Ran uninstall scripts" ' Read log file for Uninstall and check for error 1618 install in progress wscript.sleep 3000 readMSILogFile1618() wscript.echo "Read msiexec uninstall log file" oLogText.WriteLine Now & " - Read msiexec uninstall log file" If InstallInProgress = 1 then Wscript.Echo "Install in progress" oLogText.WriteLine Now & " - An installation is already in progress" UninstallEnded = 0 'Delete msi uninstall log file If fso.FileExists(MSIUninstallLog) then fso.DeleteFile MSIUninstallLog wscript.echo "Deleted msiexec uninstall log file" oLogText.WriteLine Now & " - Deleted msiexec uninstall log file" wscript.sleep 10000 ' wait 10 seconds wscript.echo "Trying uninstall again" oLogText.WriteLine Now & " - Trying uninstall again" End If End If loop wscript.echo "Uninstall loop exited" oLogText.WriteLine Now & " - Uninstall loop exited" End If 'Run silent uninstall executables for previous versions like 1.0962 'Not using msiExec, so we don't need to loop back at startup If fso.FileExists("C:\Program Files\UltraVNC\winvnc.exe") then StopService ".", "uvnc_service", True wscript.echo "Stopped uvnc service" oLogText.WriteLine Now & " - Stopped 1.0.962 UVNC service" wscript.echo "Uninstalling Previous versions 1.0.962" oLogText.WriteLine Now & " - Uninstalling Previous versions 1.0.962" If fso.FileExists("C:\Program Files\UltraVNC\unins000.exe") then WshShell.Run """C:\Program Files\UltraVNC\unins000.exe"" /VERYSILENT /NORESTART" End If If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\unins000.exe") then WshShell.Run """C:\Program Files\uvnc bvba\UltraVNC\unins000.exe"" /VERYSILENT /NORESTART" End If ' if executable still exists, delete it. If fso.FileExists("C:\Program Files\UltraVNC\winvnc.exe") then fso.DeleteFile "C:\Program Files\UltraVNC\winvnc.exe" End If End If ' Wait until uninstall has completed successfully do until UninstallEnded = 1 UninstallEnded = 1 If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe") then UninstallEnded = 0 End If If fso.FileExists("C:\Program Files\UltraVNC\winvnc.exe") then UninstallEnded = 0 End If wscript.sleep 5000 wscript.echo "Waiting for uninstall to complete" oLogText.WriteLine Now & " - Waiting for uninstall to complete" loop 'Install new version wscript.echo "Starting Install new version" oLogText.WriteLine Now & " - Starting Install new version" 'Copy install file to the client fso.CopyFile Executable, "C:\temp\UltraVnc_X64.msi", True wscript.echo "Copied install file to C:\Temp" oLogText.WriteLine Now & " - Copied install file to C:\Temp" 'Loop through the Install in case MSIexec is already running do until InstallEnded = 1 InstallEnded = 1 'Attempt Install from new path sources WshShell.Run "msiexec.exe /i c:\Temp\UltraVnc_X64.msi /qn ALLUSERS=1 /l*v C:\Temp\UltraVNCInstallLog.txt", true wscript.echo "Ran install scripts" oLogText.WriteLine Now & " - Ran install scripts" ' Read log file for Install and check for error 1618 install in progress wscript.sleep 2000 readMSIInstallLogFile1618() wscript.echo "Read msiexec Install log file" oLogText.WriteLine Now & " - Read msiexec Install log file" If MSIInstallInProgress = 1 then Wscript.Echo "An installation is already in progress" oLogText.WriteLine Now & " - An installation is already in progress" InstallEnded = 0 'Delete msi Install log file If fso.FileExists(MSIInstallLog) then fso.DeleteFile MSIInstallLog wscript.echo "Deleted msiexec install log file" oLogText.WriteLine Now & " - Deleted msiexec install log file" wscript.sleep 10000 ' wait 10 seconds wscript.echo "Trying install again" oLogText.WriteLine Now & " - Trying install again" End If End If loop wscript.echo "Install new version completed" oLogText.WriteLine Now & " - Install new version completed" 'Wait for Install to complete successfully do until InstallEnded = 1 InstallEnded = 0 If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe") then InstallEnded = 1 End If wscript.sleep 5000 wscript.echo "Waiting for install to complete" oLogText.WriteLine Now & " - Waiting for install to complete" loop 'Copy proper IPV6 .ini file to the client fso.CopyFile "\\Server\apps\Public\General\UltraVNC\ipv6\ultravnc.ini", "C:\Program Files\uvnc bvba\UltraVNC\ultravnc.ini", True 'Copy ACL file for AD permissions fso.CopyFile "\\Server\apps\Public\General\UltraVNC\company.acl", "C:\Program Files\uvnc bvba\UltraVNC\company.acl", True wscript.echo "Supplementary files have been copied" oLogText.WriteLine Now & " - Supplementary files have been copied" 'Slow script so that service exists before it is stopped wscript.sleep 7000 wscript.echo "Slept for 7 seconds" 'Stop service so we can overwrite winvnc.exe StopService ".", "uvnc_service", True fso.CopyFile "\\Server\apps\Public\General\UltraVNC\ipv6\winvnc.exe", "C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe", True wscript.echo "winvnc IPv6 has been overwritten" oLogText.WriteLine Now & " - winvnc IPv6 has been overwritten" 'Slow script so that files have copied by the time they are to be used wscript.sleep 5000 wscript.echo "Slept for 5 seconds" 'Delete shortcuts on Public desktop oLogText.WriteLine Now & " - Delete unwanted shortcuts" If fso.FileExists("C:\Users\Public\Desktop\UltraVNC Settings.lnk") then fso.DeleteFile "C:\Users\Public\Desktop\UltraVNC Settings.lnk" End If If fso.FileExists("C:\Users\Public\Desktop\UltraVNC Server.lnk") then fso.DeleteFile "C:\Users\Public\Desktop\UltraVNC Server.lnk" End If If fso.FileExists("C:\Users\Public\Desktop\vncviewer.exe.lnk") then fso.DeleteFile "C:\Users\Public\Desktop\vncviewer.exe.lnk" End If If fso.FileExists("C:\Users\Public\Desktop\UltraVNC Viewer.lnk") then fso.DeleteFile "C:\Users\Public\Desktop\UltraVNC Viewer.lnk" End If wscript.echo "Deleted shortcuts on desktop" oLogText.WriteLine Now & " - Deleted shortcuts on desktop" 'Apply ACL for AD permissions WshShell.Run """C:\Program Files\uvnc bvba\UltraVNC\MSLogonACL.exe"" /i /o ""C:\Program Files\uvnc bvba\UltraVNC\company.acl"" " wscript.echo "Applied ACL for AD permissions" oLogText.WriteLine Now & " - Applied ACL for AD permissions" 'Only mark as complete if install succeeded If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe") then wscript.echo "Install happened, proceeding with registry update" oLogText.WriteLine Now & " - Install happened, proceeding with registry update" 'Write version to the registry WshShell.RegWrite VNCRegKey,UltraVNCVersion,"REG_SZ" Set WshShell = Nothing wscript.echo "Registry updated" oLogText.WriteLine Now & " - Registry updated" wscript.echo "Delete install file from c:\temp" oLogText.WriteLine Now & " - Delete install file from c:\temp" fso.DeleteFile("C:\Temp\UltraVnc_X64.msi") 'Stop and start the service' RestartServices ".", "uvnc_service" wscript.echo "service restarted" oLogText.WriteLine Now & " - service restarted" End If wscript.echo "End of check for successful install" oLogText.WriteLine Now & " - End of check for successful install" End If wscript.echo "End of check for proper version" oLogText.WriteLine Now & " - End of check for proper version" ' Close the log file oLogText.Close ' End the script wscript.Quit ' Functions below, not necessary to modify function readFromRegistry (strRegistryKey, strDefault ) Dim WSHShell, value On Error Resume Next Set WSHShell = CreateObject("WScript.Shell") value = WSHShell.RegRead( strRegistryKey ) if err.number <> 0 then readFromRegistry= strDefault else readFromRegistry=value end if set WSHShell = nothing end function function uninstallNewPath() If fso.FileExists("C:\Program Files\uvnc bvba\UltraVNC\unins000.exe") then WshShell.Run """C:\Program Files\uvnc bvba\UltraVNC\unins000.exe"" /VERYSILENT /NORESTART" ' 1.1.9.1 uninstall End If WshShell.Run "MsiExec.exe /X{E183B283-5916-469A-9225-CEC56FEAFB35} /quiet /norestart /l*v C:\Temp\UltraVNCUninstallLog.txt",true WshShell.Run "MsiExec.exe /X{4ABD1242-7176-49CC-A128-AB9506C72DC7} /quiet /norestart /l*v C:\Temp\UltraVNCUninstallLog.txt",true '1.1.9.3 WshShell.Run "MsiExec.exe /X{88CD73D8-92BE-40F1-9D99-13B8D93253C5} /quiet /norestart /l*v C:\Temp\UltraVNCUninstallLog.txt",true '1.2.0.5 WshShell.Run "MsiExec.exe /X{77B0E545-699B-4DEC-A686-3636B9920FFC} /quiet /norestart /l*v C:\Temp\UltraVNCUninstallLog.txt",true '1.2.1.0 end function function readMSILogFile1618() If fso.FileExists(MSIUninstallLog) then InstallInProgress = 0 Set objTextFile = fso.OpenTextFile(MSIUninstallLog, ForReading, False, -1) do until objTextFile.AtEndOfStream strLine = objTextFile.ReadLine() If InStr(strLine, SearchInstallInProgress) <> 0 then InstallInProgress = 1 End If loop objTextFile.Close End If end function function readMSIInstallLogFile1618() If fso.FileExists(MSIInstallLog) then MSIInstallInProgress = 0 Set objTextFile = fso.OpenTextFile(MSIInstallLog, ForReading, False, -1) do until objTextFile.AtEndOfStream strLine = objTextFile.ReadLine() If InStr(strLine, SearchInstallInProgress) <> 0 then MSIInstallInProgress = 1 End If loop objTextFile.Close End If end function Sub RestartServices(Computer, ServiceNames) Dim ServiceName, Counter, aServiceNames 'Get the array of service names aServiceNames = split(ServiceNames,",") 'loop services from beginning, stop them For Each ServiceName In aServiceNames StopService Computer, ServiceName, True Next 'loop services from end, start them For Counter = ubound(aServiceNames) To 0 Step -1 StartService Computer, aServiceNames(Counter), True Next End Sub Sub StopService(Computer, ServiceName, Wait) Dim cimv2, oService, Result 'Get the WMI administration object Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ Computer & "\root\cimv2") 'Get the service object Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'") 'Check base properties If Not oService.Started Then ' the service is Not started wscript.echo "The service " & ServiceName & " is Not started" exit Sub End If If Not oService.AcceptStop Then ' the service does Not accept stop command wscript.echo "The service " & ServiceName & " does Not accept stop command" exit Sub End If 'wscript.echo oService.getobjecttext_ 'Stop the service Result = oService.StopService If 0 <> Result Then wscript.echo "Stop " & ServiceName & " error: " & Result exit Sub End If Do While oService.Started And Wait 'get the current service state Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'") wscript.echo now, "StopService", ServiceName, oService.Started, _ oService.State, oService.Status Wscript.Sleep 200 Loop End Sub Sub StartService(Computer, ServiceName, Wait) Dim cimv2, oService, Result 'Get the WMI administration object Set cimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ Computer & "\root\cimv2") 'Get the service object Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'") 'Path = "winmgmts:{impersonationLevel=impersonate}!\\" & Computer & _ ' "\root\cimv2:Win32_Service.Name='" & ServiceName & "'" 'Get the WMI administration object of the service 'Set oService = GetObject(Path) 'Check base properties If oService.Started Then ' the service is Not started wscript.echo "The service " & ServiceName & " is started." exit Sub End If 'Start the service Result = oService.StartService If 0 <> Result Then wscript.echo "Start " & ServiceName & " error:" & Result exit Sub End If Do While InStr(1,oService.State,"running",1) = 0 And Wait 'get the current service state Set oService = cimv2.Get("Win32_Service.Name='" & ServiceName & "'") wscript.echo now, "StartService", ServiceName, oService.Started, _ oService.State, oService.Status Wscript.Sleep 200 Loop End Sub