%sessionname% returns incorrect session name

Posted by Samuel Walker on Server Fault See other posts from Server Fault or by Samuel Walker
Published on 2012-01-23T11:18:30Z Indexed on 2014/05/31 21:33 UTC
Read the original article Hit count: 236

I have a virtualised Windows XP SP3 machine, which I am connecting to over Remote Desktop. One of my scripts needs to use the %sessionname% variable. However this returns incorrect information.

C:\>%sessionname%

constantly returns RDP-Tcp#5, instead of the value for the currently connected session (RDP-Tcp#35 or similar), as shown in Task Manager

This causes my scripts to contain incorrect information. What can I do to resolve this?

Edit Further Information: A restart appears to solve the problem for the first connection, but then subsequent connections have the numbers fall out of sync again.

© Server Fault or respective owner

Related posts about windows-xp

Related posts about remote-desktop