Elsinore

User Forum

www.screenconnect.com
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Renaming unattended sessions
ComputerElite-Jason
#1 Posted : Wednesday, January 04, 2012 8:10:11 PM
Rank: Advanced Member
Joined: 1/28/2011
Posts: 39
Location: Ontario Canada
Hey guys, i just tried to rename one of my unatteneds and had a problem with my scritped file. I know if did work can anyone give me a hand.
Thanks
Code:
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 '%Elsinore 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

if Right(OriginalImagePath,1) = """" then
OriginalImagePath = left(OriginalImagePath, len(OriginalImagePath) - 1)
end if

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

Function URLDecode(ByVal What)
'URL decode Function
'2001 Antonin Foller, PSTRUH Software, http://www.motobit.com
  Dim Pos, pPos

  'replace + To Space
  What = Replace(What, "+", " ")

  on error resume Next
  Dim Stream: Set Stream = CreateObject("ADODB.Stream")
  If err = 0 Then 'URLDecode using ADODB.Stream, If possible
    on error goto 0
    Stream.Type = 2 'String
    Stream.Open

    'replace all %XX To character
    Pos = InStr(1, What, "%")
    pPos = 1
    Do While Pos > 0
      Stream.WriteText Mid(What, pPos, Pos - pPos) + _
        Chr(CLng("&H" & Mid(What, Pos + 1, 2)))
      pPos = Pos + 3
      Pos = InStr(pPos, What, "%")
    Loop
    Stream.WriteText Mid(What, pPos)

    'Read the text stream
    Stream.Position = 0
    URLDecode = Stream.ReadText

    'Free resources
    Stream.Close
  Else 'URL decode using string concentation
    on error goto 0
    'UfUf, this is a little slow method.
    'Do Not use it For data length over 100k
    Pos = InStr(1, What, "%")
    Do While Pos>0
      What = Left(What, Pos-1) + _
        Chr(Clng("&H" & Mid(What, Pos+1, 2))) + _
        Mid(What, Pos+3)
      Pos = InStr(Pos+1, What, "%")
    Loop
    URLDecode = What
  End If
End Function

Dim MyArray, Msg
MyArray = Split(OriginalImagePath, "t=", -1, 1)
test = URLDecode(MyArray(1))

Dim Input
Input = InputBox("Enter new screenconnect computer name", ,test)
If Input = "" Then
Wscript.Echo "You entered nothing in the input box...quitting now"
wscript.quit
else
Input2 = URLEncode(Input)

newpathname = MyArray(0) & "t=" & Input2 & """"
'Wscript.Echo newpathname

strKeyPath = "SYSTEM\CurrentControlSet\services\" & temp
strValueName = "ImagePath"
strValue = newpathname
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

For Each objService in colServiceList
objService.StopService()
WSCript.Sleep 15000
objService.StartService()
next
end if
bigdessert
#2 Posted : Wednesday, January 04, 2012 9:29:49 PM
Rank: Advanced Member
Joined: 9/14/2010
Posts: 458
Location: Minnesota
ComputerElite-Jason wrote:
Hey guys, i just tried to rename one of my unatteneds and had a problem with my scritped file. I know if did work can anyone give me a hand.
Thanks
Code:
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 '%Elsinore 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

if Right(OriginalImagePath,1) = """" then
OriginalImagePath = left(OriginalImagePath, len(OriginalImagePath) - 1)
end if

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

Function URLDecode(ByVal What)
'URL decode Function
'2001 Antonin Foller, PSTRUH Software, http://www.motobit.com
  Dim Pos, pPos

  'replace + To Space
  What = Replace(What, "+", " ")

  on error resume Next
  Dim Stream: Set Stream = CreateObject("ADODB.Stream")
  If err = 0 Then 'URLDecode using ADODB.Stream, If possible
    on error goto 0
    Stream.Type = 2 'String
    Stream.Open

    'replace all %XX To character
    Pos = InStr(1, What, "%")
    pPos = 1
    Do While Pos > 0
      Stream.WriteText Mid(What, pPos, Pos - pPos) + _
        Chr(CLng("&H" & Mid(What, Pos + 1, 2)))
      pPos = Pos + 3
      Pos = InStr(pPos, What, "%")
    Loop
    Stream.WriteText Mid(What, pPos)

    'Read the text stream
    Stream.Position = 0
    URLDecode = Stream.ReadText

    'Free resources
    Stream.Close
  Else 'URL decode using string concentation
    on error goto 0
    'UfUf, this is a little slow method.
    'Do Not use it For data length over 100k
    Pos = InStr(1, What, "%")
    Do While Pos>0
      What = Left(What, Pos-1) + _
        Chr(Clng("&H" & Mid(What, Pos+1, 2))) + _
        Mid(What, Pos+3)
      Pos = InStr(Pos+1, What, "%")
    Loop
    URLDecode = What
  End If
End Function

Dim MyArray, Msg
MyArray = Split(OriginalImagePath, "t=", -1, 1)
test = URLDecode(MyArray(1))

Dim Input
Input = InputBox("Enter new screenconnect computer name", ,test)
If Input = "" Then
Wscript.Echo "You entered nothing in the input box...quitting now"
wscript.quit
else
Input2 = URLEncode(Input)

newpathname = MyArray(0) & "t=" & Input2 & """"
'Wscript.Echo newpathname

strKeyPath = "SYSTEM\CurrentControlSet\services\" & temp
strValueName = "ImagePath"
strValue = newpathname
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

For Each objService in colServiceList
objService.StopService()
WSCript.Sleep 15000
objService.StartService()
next
end if


Whats the error message it gives if any?

I have a hunch this line

Code:
%Elsinore ScreenConnect Guest Service%


needs to be

Code:
%ScreenConnect Guest Service%

Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.