Is there a tool akin to 'who' or 'w' via the command-line on Windows?

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


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

Try

WMIC /Node:remotecomputer ComputerSystem Get UserName

For example

WMIC /Node:127.0.0.1 ComputerSystem Get UserName

More information:

  • an article on Microsoft TechNet about WMIC
  • a blog post comparing WMIC with Windows Powershell Cmdlets for WMI.

Have a look at Microsofts Sysinternals tool PSLoggedOn