4

Without using something like cygwin, is there a way to find out everyone who is logged-into a Windows server form the command-line?

1

4 Answers 4

4

who:

qwinsta
query station

w, finger:

quser
query user

It is possible to write a custom tool using WTSEnumerateSessions() and WTSQuerySessionInformation() - very easy to use via Python with PyWin32:

import win32ts
protocols = {
    win32ts.WTS_PROTOCOL_TYPE_CONSOLE: "console",
    win32ts.WTS_PROTOCOL_TYPE_ICA: "citrix",
    win32ts.WTS_PROTOCOL_TYPE_RDP: "rdp",
}

## alternatively, hServer = win32ts.WTSOpenServer("hostname")
hServer = win32ts.WTS_CURRENT_SERVER_HANDLE

currentSessId = win32ts.WTSGetActiveConsoleSessionId()
for session in win32ts.WTSEnumerateSessions(hServer):
    sessionId = session["SessionId"]
    session["UserName"] = win32ts.WTSQuerySessionInformation(hServer, sessionId, win32ts.WTSUserName)
    session["WinStationName"] = session["WinStationName"] or "(disconnected)"
    session["Protocol"] = win32ts.WTSQuerySessionInformation(hServer, sessionId, win32ts.WTSClientProtocolType)
    session["ProtocolName"] = protocols.get(session["Protocol"], "unknown")
    print "%(UserName)-20s %(WinStationName)s (%(ProtocolName)s/%(SessionId)d)" % session
1
  • 1
    I think you mean query session and not query station?
    – Rami A.
    Oct 23, 2015 at 18:14
4

Try

WMIC /Node:remotecomputer ComputerSystem Get UserName

For example

WMIC /Node:127.0.0.1 ComputerSystem Get UserName

More information:

1
  • Nice. Have not heard of WMIC.
    – gravyface
    May 1, 2010 at 20:42
1

Have a look at Microsofts Sysinternals tool PSLoggedOn

1

type in query user or query user /server:remoteserver for a list of currently logged in users. This will also tell you how they are logged in. This works on standalone servers and workstations as well as terminal servers

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .