How to query for users on a machine?
First we can query to find out what users have a session on a remote machine? Windows provides the "quser" command which we can use to query for the sessions running on that machine.
The format is as follows:
quser /server:ServerName
Here is a screenshot running this command against a remote machine. Notice that it shows the User Name, state and ID of the session.
Log off User |
Notice that I have used the Session Id which I got from the above.
Note: If you remotely log off a user, their log session goes away which could mean the unsaved data is lost, or if the user in the middle of an activity, we might be in trouble.
Of course some things are easier to do using a script:
Here is the VBScript code, which allows the user to remotely log off.
strComputer = ""
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(0)
Next
Save the code in .vbs format and execute it.
No comments:
Post a Comment