logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
kilo1548  
#1 Posted : Thursday, March 15, 2018 10:37:54 PM(UTC)
kilo1548


Rank: Guest

Joined: 3/15/2018(UTC)
Posts: 1
Location: Salt Lake City

Currently when Screen Connect installs it creates a random Guid from my understanding to uniquely identify the machine.

Is it possible to have ScreenConnect change this behavior to something else?
  • Serial Number?
    Value stored in a reg key?
    Value stored in a log/txt file?


This would be amazingly helpful in our environment as we remotely image machines and would prefer that the checked back into the same Access session to ease on license true ups. We currently have almost 10,000 access agents deployed and in any one month we may end up with 300-400 Ghost access sessions from either screen Connect being manually reinstalled by a tech or a machine being reimaged.

Any help on this would be greatly appreciated.

Thanks
Scott  
#2 Posted : Monday, March 19, 2018 11:51:42 AM(UTC)
Scott


Rank: Administration

Medals: Level 4: Wise Old Owl! Received 100 Thanks!

Joined: 3/28/2014(UTC)
Posts: 2,731
United States

Thanks: 3 times
Was thanked: 336 time(s) in 290 post(s)
So, in general we do not recommend altering how a SessionID is generated. I know there are a few circumstances where this can be problem (especially with imaged machines in your example), but it can cause more headache in the future.

What I would recommend is that you potentially look at the 'Set Session Properties from System Variables' extension which can change a session's custom properties based upon a system variable.
ScreenConnect Team
shawnkhall  
#3 Posted : Tuesday, March 27, 2018 5:25:43 PM(UTC)
shawnkhall


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 2/6/2014(UTC)
Posts: 294
Man
United States

Thanks: 7 times
Was thanked: 25 time(s) in 22 post(s)
Hi, @kilo1548,

I have to image a bunch of devices for one of our clients. you really just need to modify the service definition to use a new GUID for the "s=" parameter. As luck would have it, I wrote a script specifically to address this problem. I've made it as generic as possible specifically so other people could benefit from it. It also has the ability to assign a specific GUID to a device should you need that capability (I did). With the GUID-assignment feature you could set the first 2 groups to represent a specific client or dept, for example. Or you could use it to re-create your image from one of your clones so that it is as consistent as possible. Or to emulate another device to test out commands or whatever. I've found several effective use-cases for it.

It works very well, though you must REBOOT (not simply RESTART the service) if you are using it from within the Commands feature, since restarting the service there kills the process that's trying to restart the service, resulting in the service not coming back up.

Save it as newscid.vbs and call it like so:
Code:
cscript.exe //nologo newscid.vbs reboot new

or
Code:
cscript.exe //nologo newscid.vbs reboot 12345678-1234-1234-1234-1234567890ab

You can even use an extension to run this from the Commands for a specific device GUID so that it will automatically run every single time one of the vanilla clones comes online (add whatever other customizations you need to it as well and you've got an easy way to prep 'em all). :)


Code:
'//=============================================================================
 ' "NewSCID"
 ' Displays or resets the active device GUID for SC.
 ' If you pass "new" it resets the GUID, essentially creating a new instance.
 '//============================================================================
 ' Love it? There's more where this came from. 12pd.com
 '//============================================================================
Const kVersion = "1.1.0"
' default settings
Const kService = "ScreenConnect Client%"	' service pattern name to match
Const kReboot  = 0		' reboot computer? 0=no, 1=yes
Const kRestart = 1		' restart service? 0=no, 1=yes
Const kWaitMax = 30		' seconds; increase wait time for slow machines
Const kBackup  = 0		' backup GUID? 0=no, 1=yes
'//=============================================================================
WScript.Echo "NewSCID " & kVersion
'//=============================================================================


'//=============================================================================
' variables
Dim oArgs, lIter, ksFilter
Dim lReboot, lRestart, iWaitMax, lBackup
Dim sOldSCGuid, sNewSCGuid

' apply defaults
lReboot  = kReboot
lRestart = kRestart
iWaitMax = kWaitMax
lBackup  = kBackup
sNewSCGuid = ""

' parse input
Set oArgs = WScript.Arguments
If oArgs.Count > 0 Then
	For lIter = 0 To oArgs.Count-1
		ksFilter = LCase(oArgs(lIter))
		Select Case True
			' help
			Case ((ksFilter = "/?") Or (ksFilter = "/help") Or (ksFilter = "help"))
				WScript.Echo "NewSCID " & kVersion
				WScript.Echo "Displays or resets the active device GUID for SC."
				WScript.Echo ""
				WScript.Echo "Usage:"
				WScript.Echo "  NewSCID <options>"
				WScript.Echo ""
				WScript.Echo "Examples:"
				WScript.Echo "  NewSCID /?"
				WScript.Echo "  NewSCID "
				WScript.Echo "  NewSCID new [#]"
				WScript.Echo "  NewSCID reboot new"
				WScript.Echo "  NewSCID <guid> restart 10"
				WScript.Echo ""
				WScript.Echo "Options:"
				WScript.Echo "              The default behavior is to display the SC GUID."
				WScript.Echo "  /?          Displays this help text."
				WScript.Echo "  new         Assigns a new random GUID, essentially creating a new instance (ideal for cloned devices)."
				WScript.Echo "  restart     Restart the service after updating the GUID. This should only be used interactively on-device, not through the SC Command feature."
				WScript.Echo "  #           Any whole number, representing seconds, to wait for each service to stop or start."
				WScript.Echo "  norestart   Disable service restart."
				WScript.Echo "  reboot      Restart the computer after updating the GUID. This option is ideal for use within the SC Command feature."
				WScript.Echo "  noreboot    Disable reboot."
				WScript.Echo "  backup      Create a backup of the current GUID to ""%curdir%\sc-%timestamp%.log""."
				WScript.Echo "  nobackup    Do no create a backup."
				WScript.Echo ""
				
			' check for GUID input
			Case (Len(ksFilter) = 36)
				sNewSCGuid = ksFilter

			' new
			Case (ksFilter = "new")
				sNewSCGuid = GuidGen()

			' adjust max wait time
			Case (IsNumeric(ksFilter))
				iWaitMax = CInt(ksFilter) ' seconds

			' reboot
			Case (ksFilter = "reboot")
				lReboot = 1

			' noreboot
			Case (ksFilter = "noreboot")
				lReboot = 0

			' restart
			Case (ksFilter = "restart")
				lRestart = 1

			' norestart
			Case (ksFilter = "norestart")
				lRestart = 0

			' backup
			Case (ksFilter = "backup")
				lBackup = 1

			' nobackup
			Case (ksFilter = "nobackup")
				lBackup = 0
		End Select
	Next
End If


'//=============================================================================
' view or change?
If sNewSCGuid = "" Then
	' parse existing - we will only display it
	sOldSCGuid = SCGuid()
	WScript.Echo "SCGuid is " & sOldSCGuid
Else
	' parse old
	sOldSCGuid = SCGuid()
	WScript.Echo "SCGuid was " & sOldSCGuid

	' announce new
	WScript.Echo "SCGuid will be " & sNewSCGuid

	' set new
	sNewSCGuid = SCGuidSet(sNewSCGuid)
	WScript.Echo "SCGuid is " & sNewSCGuid

	' reboot/restart
	If (lReboot) Then
		Call RebootDevice()
	ElseIf (lRestart) Then
		Call RestartService()
	End If
End If
'//=============================================================================


'//=============================================================================
Function RebootDevice()
	Dim oShell
	Set oShell = CreateObject("WScript.Shell")
	WScript.Echo "Rebooting"
	oShell.Run "%comspec% /c shutdown /r /t 0 /f", "", TRUE
	Set oShell = Nothing
End Function
'//=============================================================================


'//=============================================================================
Function RestartService()
	Dim scName, oQuery, oWMI, cService
	Dim iWait
	
	' parse services
	Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
	Set oQuery = oWMI.ExecQuery("Select * from Win32_Service where Name like '" & kService & "'")
	For each cService in oQuery
		scName = Trim( cService.Name )
		WScript.Echo "Restarting " & scName
		
		' stop the service
		iWait = 0
		cService.StopService()
		Do
			If cService.State = "Stopped" Then
				Exit Do
			End If
			Call Sleep(1)
			iWait = iWait + 1
		Loop Until iWait = iWaitMax
		WScript.Echo "Stopped: " & scName
		
		' start the service
		iWait = 0
		cService.StartService()
		Do
			If cService.State = "Running" Then
				Exit Do
			End If
			Call Sleep(1)
			iWait = iWait + 1
		Loop Until iWait = iWaitMax
		WScript.Echo "Started: " & scName
	Next
	
End Function
'//=============================================================================


'//=============================================================================
Function SCGuidSet(sNewGuid)
	On Error Resume Next
	Dim oReg, kRoot, sKey, sEntry, sValue, aVersion, lIter, aParts
	Dim scName, oQuery, oWMI, cService, sOldGuid
	kRoot = &H80000002
	
	' parse services
	Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
	Set oQuery = oWMI.ExecQuery("Select * from Win32_Service where Name like '" & kService & "'")
	For Each cService in oQuery
		scName = Trim( cService.Name )
		sKey = "SYSTEM\CurrentControlSet\services\" & scName
		sEntry = "ImagePath"
		oReg.GetExpandedStringValue kRoot, sKey, sEntry, sValue
		
		' parse the SC service for relevant data
		aVersion = Split( sValue, "&" )
		For lIter = 0 to UBound(aVersion)
			aParts = Split(aVersion(lIter), "=")
			If aParts(0) = "s" Then
				sOldGuid = aParts(1)
				Exit For
			End If
		Next
		
		' record it if necessary
		If (lBackup = 1) Then
			Call LogSCID(scName & vbTab & sOldGuid)
		End If
		
		' update it with the new SC Guid
		sValue = Replace(sValue, sOldGuid, sNewGuid)
		oReg.SetExpandedStringValue kRoot, sKey, sEntry, sValue
		sNewGuid = SCGuid()
	Next
	
	' return
	Set cService = Nothing
	Set oQuery = Nothing
	Set oWMI = Nothing
	Set oReg = Nothing
	SCGuidSet = sNewGuid
End Function
'//=============================================================================


'//=============================================================================
Function SCGuid()
	On Error Resume Next
	Dim oReg, kRoot, sKey, sEntry, sVersion, aVersion, lIter, aParts
	Dim scName, oQuery, oWMI, cService
	kRoot = &H80000002

	' parse services
	Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
	Set oQuery = oWMI.ExecQuery("Select * from Win32_Service where Name like '" & kService & "'")
	For each cService in oQuery
		scName = Trim( cService.Name )
		sKey = "SYSTEM\CurrentControlSet\services\" & scName
		sEntry = "ImagePath"
		oReg.GetStringValue kRoot, sKey, sEntry, sVersion
		If sVersion = "" Then oReg.GetExpandedStringValue kRoot, sKey, sEntry, sVersion

		' parse the SC service for relevant data
		aVersion = Split( sVersion, "&" )
		sVersion = ""
		For lIter = 0 to UBound(aVersion)
			aParts = Split(aVersion(lIter), "=")
			If aParts(0) = "s" Then
				sVersion = aParts(1)
				Exit For
			End If
		Next
		
		' record it if necessary
		If (lBackup = 1) Then
			Call LogSCID(scName & vbTab & sVersion)
		End If
	Next
	
	' return
	Set cService = Nothing
	Set oQuery = Nothing
	Set oWMI = Nothing
	Set oReg = Nothing
	SCGuid = sVersion
End Function
'//=============================================================================


'//=============================================================================
Function LogSCID(sLog)
	Dim sFile, oFSO, tsFile
	sFile = "sc-" & ISO8601T(Now) & ".txt"
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set tsFile = oFSO.OpenTextFile( sFile, 1, 0 )
		tsFile.WriteLine sLog
		tsFile.Close
	Set tsFile = Nothing
	Set oFSO = Nothing
End Function
'//=============================================================================


'//=============================================================================
Function ISO8601T(dDate)
' yyyymmddThhnnss format
	ISO8601T = Year( dDate ) _ 
		& Right("0" & Trim ( Month( dDate ) ), 2) _ 
		& Right("0" & Trim ( Day( dDate ) ), 2) & "T" _ 
		& Right("0" & Trim ( Hour( dDate ) ), 2) _ 
		& Right("0" & Trim ( Minute( dDate ) ), 2) _ 
		& Right("0" & Trim ( Second( dDate ) ), 2)
End Function
'//=============================================================================


'//=============================================================================
Sub Sleep(ByVal iSeconds)
	Dim dStart, bDone
	dStart = Now()
	bDone = False
	While Not bDone
		If DateDiff("s", dStart, Now()) >= CInt(iSeconds) Then
			bDone = True
		End If
	Wend
End Sub
'//=============================================================================


'//=============================================================================
Function GuidGen()
	Dim oTypeLib, sNewGuid
	' create a new guid
	Set oTypeLib = CreateObject("Scriptlet.TypeLib")
	sNewGuid = LCase(oTypeLib.Guid)
	Set oTypeLib = Nothing
	' trim Null
	sNewGuid = Left(sNewGuid, Len(sNewGuid)-2)
	' remove braces
	sNewGuid = Replace(sNewGuid, "{", "")
	sNewGuid = Replace(sNewGuid, "}", "")
	' return
	GuidGen = sNewGuid
End Function
'//=============================================================================

thanks 1 user thanked shawnkhall for this useful post.
KatyComputer on 5/2/2018(UTC)
shawnkhall  
#4 Posted : Tuesday, April 17, 2018 4:52:19 PM(UTC)
shawnkhall


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 2/6/2014(UTC)
Posts: 294
Man
United States

Thanks: 7 times
Was thanked: 25 time(s) in 22 post(s)
btw, I had to better-identify a group of imaged devices and was able to use the NEWSCID script above along with 'getmac' to assign a unique ScreenConnect ID/GUID to each instance that included the MAC address (with the hyphens removed) as a portion of the replacement GUID:

Code:
FOR /F "tokens=1,2" %%K IN ('getmac ^| find "Tcpip"') DO SET theMAC=%%K
SET theMAC=%theMAC:-=%
cscript //nologo newscid.vbs restart 12345678-1111-2222-3333-%spcMAC% 

Edited by user Tuesday, April 17, 2018 4:52:58 PM(UTC)  | Reason: Not specified

thanks 1 user thanked shawnkhall for this useful post.
KatyComputer on 5/2/2018(UTC)
Users browsing this topic
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.