Environment variable clientname scope on terminal server

batchenvironment-variablesterminal-serverwindows-server-2008-r2

I have a script that needs the CLIENTNAME environment variable, it runs on a terminal server.
I have a batch file for testing that contains:
set CLIENTNAME; pause

If I RDP as an admin:
If I open a command prompt, run the script, it shows the clientname.
If I double click on the script, the CLIENTNAME variable does not exist.

If I Login from igel/wyse terminal:
If I double click on the same script, the it shows the clientname.

Other details: 2008R2, Xenapp 6.5, testing as a domain admin.

What's happening with the environment variable CLIENTNAME?
Why doesn't it exist when I double click on the batch file if I am RDPd to the server but does exist if a command prompt is already open?
All the other environment variables seem to be there.

Best Answer

SYMPTOMS When connecting remotely with Remote Desktop Connection, the environment variables CLIENTNAME and SESSIONNAME are added to each process that is started.

If you set the Folder Option "Launch folder windows in a separate process" and later launch an application from an additional Explorer window, the application will not see these additional environment variables.

CAUSE The additional Explorer window is not a child window of the parent Explorer.exe process, but launched from the system process. Therefore it does not inherit the environment from the Explorer main window.

RESOLUTION If your application relies on these variables, remove the folder option "Launch folder windows in a separate process".

Clientname and Sessionname enviroment variable may be missing

Quotation: Clientname and Sessionname enviroment variable may be missing.