Tuesday 2 June 2015

Check remotely who is currently logged on to Windows workstation

What:

Windows 7, Windows 8

Problem:

You would like to check who is currently logged to PC without disturbing a user.

Solution:

Do it via command line

WMIC /NODE: "<hostname>" COMPUTERSYSTEM GET USERNAME

- use hostname or ip address

Do it with VBS script

On error resume next
strComputer = InputBox("Type in the name of the computer you want to query.")
    If strComputer > "" Then
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

    Else
    Wscript.Quit
    End If

Wscript.Quit

No comments:

Post a Comment