About vbscript logoff rdp sessions

Asked By 10 points N/A Posted on -
qa-featured

I have problems with vbscript logoff rdp sessions. I want to log off user and disable access to a published application that is in the software. How can I do this?

 

SHARE
Answered By 565895 points N/A #159907

About vbscript logoff rdp sessions

qa-featured

To log off a user from his or her workstation, you need to be an administrator. You can use some DOS commands to forcibly log off a user from the computer. First of all, you need to know first which terminals are still being used by users. The quser command can be used to query for the sessions that are still running on a specific workstation. The correct syntax for the command is:

  • quser /server:ServerName

Where “quser<space>/<server>:<ServerName>”. Here is a sample screenshot of the command when it is run against a remote machine.

The next problem would be is how you would be able to log off a user from that specific terminal. There is a command called logoff that can be used to forcibly log off a user from his or her workstation based on their session ID. The correct syntax for the command is:

  • logoff SessionId /Server:ServerName

Where “logoff<space><SessionId><space>/<Server>:<ServerName>”. Here is an example screenshot of the command being executed on the command prompt:

To apply these commands on a VBScript, you’ll probably get the script below. Save this script in .vbs format and then run it.

strComputer = ""

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems

ObjOperatingSystem.Win32Shutdown(0)

Login/Register to Answer

Related Questions