Who Is Logged On?

If you need to determine who is logged into a Windows system, there are several alternatives for collecting that information from a command line interface. One of method is to use a Visual Basic script to determine who is logged on, such as the WhoLogon.vbs script by Guy Thomas. For details on the code within the script below, see WMI - Who is Logged on at That Computer?.

' WhoLogon.vbs
' Sample VBScript to discover which user is logged on
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.2 - December 2005
' --------------------------------------------------------------'
Option Explicit
Dim objWMIService, objComputer, colComputer, strComputer

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
Wscript.Echo objComputer.UserName & " is logged on"
Next

' End of Sample Script. Who is logged on?

The script will report the logged on user for the system on which it is run. To run the script from a command line and see the results displayed in a small window, type WhoLogon in the directory whee it is installed. To run it from the command line and see the results displayed in text form at the command line, type cscript whologon.vbs (include the /nologo option, if you don't want to see the Windows Host version number and Microsoft copyright display).


C:\Program Files\Utilities\VBScript>cscript /nologo whologon.vbs
PLUTO\Pam is logged on

In the above example, the user had reported that she couldn't access her favorites in Internet Explorer and that Outlook wasn't working properly. I was able to connect to the system remotely using OpenSSH for Windows to obtain a command line interface. When I ran the WhoLogon script, I could see that she was logged in to the local Pam account on the system, Pluto, rather than into a domain account with the same name, which explained why she didn't see the favorites she normally would see.

Another VBS script to display a logged on computer, which can also be used to display the user logged into a remote system, is LoggedOn.vbs by Cheyenne Harden.

Another alternative for determining who is logged into a system is to use the free PsLoggedOn utility by Mark Russinovich at Sysinternals. This can be downloaded separately or as part of the PsTools package.

There is a whoami utility within the Native Win32 ports of some GNU utilities, which contains ports of some common GNU utilities to native Win32. In this context, native means the executables depend only on the Microsoft C-runtime DLL msvcrt.dll and not an emulation layer like that provided by Cygwin tools.

References:

  1. A Tutorial in VBScript
  2. WMI - Who is Logged on at That Computer?
  3. eBooks from Guy Thomas
  4. PsLoggedOn
  5. Native Win32 ports of some GNU utilities
  6. LoggedOn.vbs