How can I retrieve the current user session ID via windows command line?

link|improve this question
I'm not sure what you mean by session ID? – EBGreen Jun 29 '11 at 14:19
In the tasklist under the users tab, each user is associated with a session ID. I want to retrieve this via command line so I can use it for a remote application. – Negative Jun 29 '11 at 14:30
feedback

2 Answers

up vote 1 down vote accepted

This is certainly not the most efficient way, but you can take a look at 'tasklist'. It will display the name and session# of each process running. If you are logged in locally then look at the ID for the session named "console".


Edit
The command Query Session will accomplish this.

link|improve this answer
I'm looking to retrieve it via command line. – Negative Jun 29 '11 at 14:29
1  
Right, from the command line, type tasklist. – Gary Jun 29 '11 at 14:30
Hmm actually you might be on to something here. edit: tasklist /FI "imagename eq cmd.exe" /FO list I plan on parsing this output. Thanks! – Negative Jun 29 '11 at 14:35
Or I can do that. Nice – Negative Jun 29 '11 at 14:36
feedback

Unlike the Session Name, the Session ID is not stored in a variable and is not as easy to get to. I am sure there is one, but I can't think of a built in command line tool that does this.

However, I have written a tiny .exe file (C#, .Net 4) that does this.

It will both display the session id, and also have it as the return code so that you can use this in a variety of scripts/techniques.

Link to file on MediaFire

link|improve this answer
@Kcotreau - i.imgur.com/5mUFJ.png – William Hilsum Jun 29 '11 at 14:42
I realized. :). – KCotreau Jun 29 '11 at 14:44
feedback

Your Answer

 
or
required, but never shown

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