I am trying to set certain environment variables on a Windows 2012 R2 Remote Session Host based on the client machine. I have configured a login script to set the variable, and it does work, but not when set a a login script.
Here is the vb script:
Set objShell = CreateObject("WScript.Shell") Set objEnv = objShell.Environment("USER") client=objShell.ExpandEnvironmentStrings("%ClientName%") Select Case client Case "Workstation1" objEnv("Variable") = "Variable Data1" Case "Workstation2" objEnv("Variable") = "Variable Data2" End Select
If I run this script, the variable gets set correctly. But if it is set as a logon script, it is not retrieving the client name. I assume this is due to the fact that the terminal session hasn't fully initialized when the script is executed.
I have made sure that 'Run logon scripts synchronously' is disabled and even set a delay in the script, but it still won't work.
Any suggestions would be appreciated.