|
Rank: Advanced Member Joined: 9/14/2010 Posts: 458 Location: Minnesota
|
I updated my script to allow for changing the relay url/ip and the port during the upgrade. Also, it does a proper uninstall/install of the msi so now it updates the url in add/remove programs and correct version in add/remove programs. Code:'===========CHANGE TO YOUR DOMAIN================== '======example: http://domain.com:port============= BASEURL = "http://domain.com" 'can be an ip or a url leave empty to not change DO NOT PUT HTTP:// OR HTTPS:// newrelayurl = "" 'leave empty to not change port otherwise enter the port number newrelayport = ""
'=========NO NEED TO CHANGE BELOW================== '=========NO NEED TO CHANGE BELOW================== '=========NO NEED TO CHANGE BELOW================== strComputer = "." 'could be any computer, not just the local one ' Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name LIKE '%ScreenConnect Guest Service%'") dim temp dim OriginalImagePath For Each objService in colServiceList temp = objService.DisplayName next
const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = "SYSTEM\CurrentControlSet\services\" & temp strValueName = "ImagePath" oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue OriginalImagePath = strValue 'Wscript.Echo OriginalImagePath 'Find Y Dim MyArrayYFirst Dim MyArrayYSecond Dim y MyArrayYFirst = Split(OriginalImagePath, "y=", -1, 1) MyArrayYSecond = Split(MyArrayYFirst(1), "&", -1, 1) y = MyArrayYSecond(0) 'Wscript.Echo y 'Find H Dim MyArrayHFirst Dim MyArrayHSecond Dim h MyArrayHFirst = Split(OriginalImagePath, "h=", -1, 1) MyArrayHSecond = Split(MyArrayHFirst(1), "&", -1, 1) If newrelayurl = "" Then h = MyArrayHSecond(0) Else h = newrelayurl End If 'Wscript.Echo h 'Find P Dim MyArrayPFirst Dim MyArrayPSecond Dim p MyArrayPFirst = Split(OriginalImagePath, "p=", -1, 1) MyArrayPSecond = Split(MyArrayPFirst(1), "&", -1, 1) If newrelayport = "" Then p = MyArrayPSecond(0) Else p = newrelayport End If 'Wscript.Echo p 'Find K Dim MyArrayKFirst Dim MyArrayKSecond Dim k MyArrayKFirst = Split(OriginalImagePath, "k=", -1, 1) MyArrayKSecond = Split(MyArrayKFirst(1), "&", -1, 1) k = MyArrayKSecond(0) 'Wscript.Echo k 'Find a Dim MyArrayAFirst Dim MyArrayASecond Dim a MyArrayAFirst = Split(OriginalImagePath, "a=", -1, 1) MyArrayASecond = Split(MyArrayAFirst(1), "&", -1, 1) a = MyArrayASecond(0) 'Wscript.Echo a 'Find T Dim MyArrayTFirst Dim MyArrayTSecond Dim t MyArrayTFirst = Split(OriginalImagePath, "t=", -1, 1) MyArrayTSecond = Split(MyArrayTFirst(1), "&", -1, 1) t = Replace(MyArrayTSecond(0), """","") 'Wscript.Echo t
Function URLEncode(ByVal str) Dim strTemp, strChar Dim intPos, intASCII strTemp = "" strChar = "" For intPos = 1 To Len(str) intASCII = Asc(Mid(str, intPos, 1)) If intASCII = 32 Then strTemp = strTemp & "+" ElseIf ((intASCII < 123) And (intASCII > 96)) Then strTemp = strTemp & Chr(intASCII) ElseIf ((intASCII < 91) And (intASCII > 64)) Then strTemp = strTemp & Chr(intASCII) ElseIf ((intASCII < 58) And (intASCII > 47)) Then strTemp = strTemp & Chr(intASCII) Else strChar = Trim(Hex(intASCII)) If intASCII < 16 Then strTemp = strTemp & "%0" & strChar Else strTemp = strTemp & "%" & strChar End If End If Next URLEncode = strTemp End Function If newrelayurl = "" Then urltest5 = "Bin%2fElsinore.ScreenConnect.GuestClient.msi&Property(ProductName).Value=" & URLEncode(temp) & "&ServiceInstall(ServiceInstall).Arguments=" Else temp = "ScreenConnect Guest Service ("&newrelayurl&")" urltest5 = "Bin%2fElsinore.ScreenConnect.GuestClient.msi&Property(ProductName).Value=" & URLEncode(temp) & "&ServiceInstall(ServiceInstall).Arguments=" End If
urltest = "?y=" & y & "&h=" & h & "&p=" & p & "&k=" & k & "&a=" & a & "&t=" & t
urltest1 = URLEncode(urltest)
SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
strComputer = "." 'could be any computer, not just the local one ' Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name LIKE '%ScreenConnect Guest Service%'") For Each objService in colServiceList objService.StopService() Next
BASEURL2 = "/TransformInstaller.axd?_Installer="
urltest2 = BASEURL & BASEURL2 & urltest5 & urltest1
Set wshShell = CreateObject("WScript.Shell") tempPath = wshShell.ExpandEnvironmentStrings("%TEMP%") PATH = tempPath & "\Elsinore.ScreenConnect.GuestClient.msi"
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", urltest2, false objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream") objADOStream.Open objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject") If objFSO.Fileexists(PATH) Then objFSO.DeleteFile PATH Set objFSO = Nothing
objADOStream.SaveToFile PATH objADOStream.Close Set objADOStream = Nothing End if
Set objXMLHTTP = Nothing
'Run the export package to register the DCOM component
On Error Resume Next
'********************************************************************** const AppName = "ScreenConnect Guest Service" '**********************************************************************
Set WshShell = WScript.CreateObject("WScript.Shell")
'First, find the GUID strComputer = "." Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ strComputer & "\root\default:StdRegProv") '*******************************RUN 32BIT****************************** strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys InstalledAppName = "" InstalledAppName = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")
If InStr(InstalledAppName, AppName) > 0 then RawGUID = "" GUID = "" RawGUID = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\UninstallString") GUID = Mid(RawGUID, instr(RawGUID, "{"), 38) If GUID<>"" then ' Found matching GUID, removing... WshShell.Run "msiexec /qn /x " & GUID & " REBOOT=REALLYSUPRESS" Exit For End If End If Next '*******************************RUN 64BIT****************************** strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys InstalledAppName = "" InstalledAppName = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\DisplayName")
If InStr(InstalledAppName, AppName) > 0 then RawGUID = "" GUID = "" RawGUID = WshShell.RegRead("HKLM\" & strKeyPath & "\" & subkey & "\UninstallString") GUID = Mid(RawGUID, instr(RawGUID, "{"), 38) If GUID<>"" then ' Found matching GUID, removing... WshShell.Run "msiexec /qn /x " & GUID & " REBOOT=REALLYSUPRESS" Exit For End If End If Next
WSCript.Sleep 30000
Dim WshShell Set WshShell = CreateObject("Wscript.Shell") WshShell.Run(PATH) set WshShell = Nothing
WSCript.Sleep 30000
For Each objService in colServiceList objService.StartService() Next
|