Skip
(Fresh Scripter)
2011-08-02 10:14 PM
Client ID using GetSessionID()

Hello,

We have a bunch of thin clients and are upgrading our terminal servers from 2003 to 2008 R2. 2008 R2 now creates a subkey named the TS Session ID for the session number and puts the "ClientName" in it. With that being said, I hacked at this a bit and it is working. Thought I would share and ask for some constructive criticism, as I am very much a hack at this. Thanks All.

GetSessionID() is a sweet little UDF by pearly

 Code:
$session = GetSessionID() 
? $session

$UserSID = "HKEY_USERS\" + @SID 

$ClientName = @WKSTA
	
If InStr(@PRODUCTTYPE,"Server") and InStr(@PRODUCTTYPE,"2008")
	$ClientName = ReadValue($UserSID + "\Volatile Environment\" + $Session,"CLIENTNAME")
ENDIF

If InStr(@PRODUCTTYPE,"Server") and InStr(@PRODUCTTYPE,"2003")
	$ClientName = ReadValue($UserSID + "\Volatile Environment","CLIENTNAME")
ENDIF


AllenAdministrator
(KiX Supporter)
2011-08-02 10:48 PM
Re: Client ID using GetSessionID()

Nothing wrong with your code. I like working with functions better so maybe something like this...

untested, requires getsessionid()

? clientname()
 Code:
function Clientname()
  select
    case InStr(@PRODUCTTYPE,"Server 2008")
      $ClientName = ReadValue("HKEY_USERS\" + @SID  + "\Volatile Environment\" + getsessionid(),"CLIENTNAME")
    case InStr(@PRODUCTTYPE,"Server 2003")
      $ClientName = ReadValue("HKEY_USERS\" + @SID  + "\Volatile Environment","CLIENTNAME")
    case 1  
      $ClientName = @WKSTA
  endselect
endfunction


Skip
(Fresh Scripter)
2011-08-03 05:18 PM
Re: Client ID using GetSessionID()

That function works perfect. Thanks for taking the time to clean it up and reply. Most appreciated.