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.

link|improve this question
are you trying to run this as a local user or a domain user (assuming you have a domain)? – Split71 Jan 23 at 14:47
local user, there is no domain configured on these machines. – Samuel Walker Jan 23 at 15:24
Adding Further information, a restart appears to correct the problem, but only for the first reconnection. The numbers then get out of sync again. – Samuel Walker Jan 24 at 10:11
I've put in a workaround for the moment, but I'm still concerned as to why this variable is incorrect most of the time. – Samuel Walker Jan 25 at 14:17
feedback

1 Answer

I'm not sure why it doesn't update properly, but perhaps you can use the ouput of query session instead? It's a bit more detailed as well.

link|improve this answer
Hmm... C:\>query session Fails, query is not recognized. This happens on all our of XP VM's. I suspect there may be a deeper issue here. – Samuel Walker Jan 23 at 13:48
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.