You could get the client name from the %CLIENTNAME% environment variable on a Server 2003 terminal server and get your logon script to do different things depending on its value.
Using VBScript you could do oShell.ExpandEnvironmentStrings(“%CLIENTNAME%”).
Try this on a Server 2008 R2 (including XenApp 6) server and you’ll just get %CLIENTNAME% back. Not very helpful.
Note that my logon script is configured via Group Policy: User Configuration, Policies, Windows Settings, Scripts (Logon/Logoff).
I’m guessing that they run a little too early, before the session is fully initialised.
However all is not lost, it is possible to get the client name, but it’s a bit more of a round about route!
The following is all VBScript:
Function sessionNumber Dim oShell, oExec, sOutput, iUserPos, iUserLen, iStatePos Set oShell = CreateObject("WScript.Shell") Set oExec = oShell.Exec("query session %username%") sOutput = LCase(oExec.StdOut.ReadAll) iUserPos = InStr(sOutput,LCase(oShell.ExpandEnvironmentStrings("%username%"))) iStatePos = InStr(sOutput,"active") iUserLen = Len(oShell.ExpandEnvironmentStrings("%username%")) sessionNumber = CInt(Trim(Mid(sOutput,iUserPos+iUserLen,iStatePos-iUserPos-iUserLen))) End Function Function clientName Dim oShell Set oShell = CreateObject("WScript.Shell") On Error Resume Next clientName = LCase(oShell.RegRead("HKCU\Volatile Environment\"&sessionNumber&"\CLIENTNAME")) If Err.Number<>0 Then clientName = "unknown" End If End Function WScript.Echo clientName
So we get the session number by parsing the output from the Query Session command, then use this to read the client name from the user’s registry. Luckily the registry does seem to be present and correct even though the environment variables themselves are not yet readable.
Because the above functions execute the Query Session command each time they’re run, you’re probably best stuffing the output of clientName into a something global (variable, dictionary, array – you choose) rather than calling the function every time you need the client name.