ActiveXperts Network Monitor

Quicklinks

Scripts to manage Logon Sessions

Identifying the User Logged on to a Remote Computer
Retrieving Logon Session Information

Identifying the User Logged on to a Remote Computer


Returns the user name of the user currently logged on to a remote computer. To use this script, replace RemoteComputer with the name of the remote computer you want to check.
strComputer = "RemoteComputer"
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
Next

Retrieving Logon Session Information


Returns information about logon sessions associated with the user currently logged on to a computer.
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogonSession")
For Each objItem in colItems
    Wscript.Echo "Authentication Package: " & objItem.AuthenticationPackage
    Wscript.Echo "Logon ID: " & objItem.LogonId
    Wscript.Echo "Logon Type: " & objItem.LogonType
    Wscript.Echo "Start Time: " & objItem.StartTime
    Wscript.Echo
Next