Can I find the session ID for a user logged on to another machine?

44,714

Solution 1

You can use the qwinsta (or query session) tool to list all Terminal Server sessions.

Some servers allow to use it remotely directly:

qwinsta /server remotehost

In most cases, though, you'll have to run it through psexec:

psexec \\remotehost qwinsta

Solution 2

You can try the PowerShell version:

Get-Process powershell | Select-Object SessionId | Format-List

or the MSDOS batch version:

tasklist /FI "IMAGENAME eq tasklist.exe" /FI "USERNAME eq %USERNAME%" /FO LIST | find "Session#:"

Solution 3

psexec does not require a session id.

Solution 4

Using Process Explorer on the computer you can use the Users menu to determine the session ID. The number at the beginning of each entry in the menu is the session ID.

It looks like typically you should be able to use 0 for the default session.

Share:
44,714
Dan Tao
Author by

Dan Tao

Author of the blog The Philosopher Developer and the open source libraries lazy.js and nearest-color (among others), and cohost of the podcast Spaceflix. GitHub: dtao Twitter: @dan_tao SoundCloud: dantao I’m the Head of Engineering for Bitbucket Cloud. Previously I've worked at Google, Cardpool, and ThoughtWorks.

Updated on September 17, 2022

Comments

  • Dan Tao
    Dan Tao over 1 year

    I want to open an application on another computer on the same network via the command line. The scenario here is that the user is in a room surrounded by about 20 computers and wants to be able to launch the same app on every computer without walking from screen to screen opening it up on each individual machine. I've discovered that I can get the basic functionality for this using PsExec as follows:

    psexec \\[computer] -u [username] -p [password] -d -i [SessionID] [program]
    

    For computer, username, password, and program, I'm good. Does anyone know of a way I can figure out which SessionID is assigned to a particular user logged on to a particular machine on the network? Alternately, is there a better way to go about what I'm trying to accomplish?

  • Dan Tao
    Dan Tao about 14 years
    Looks quite useful; however, I'm looking for the session ID assigned to a user on another computer. It looks like Process Explorer is only applicable to the machine on which it is running. Is that right?
  • heavyd
    heavyd about 14 years
    Yes that is true. I haven't found a way to do this remotely.
  • user1686
    user1686 almost 11 years
    It doesn't require a session ID in the sense that it simply defaults to 0, but that default is useless if there are multiple users logged in and you want to pick a specific one.