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?

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
    I think you mean query session and not query station? – Rami A. Oct 23 '15 at 18:14
4

Try

WMIC /Node:remotecomputer ComputerSystem Get UserName

For example

WMIC /Node:127.0.0.1 ComputerSystem Get UserName

More information:

  • Nice. Have not heard of WMIC. – gravyface May 1 '10 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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