How do you log off a Terminal Server session user via WSH script?

How do you log off a Terminal Server session user via WSH script?

Post by krausss » Fri, 21 Jan 2005 06:33:16


Is there some way which will let me force a user to log off from a
terminal server session while running a script and get an error. In my
particular case, I am mapping drives and if I can't map a drive for
some reason, I do a check which will display a message box telling the
user about the drive mapping problem, but once they hit the OK button I
want to be able to force them off (to be automatically logged off from
the terminal server, closing their rdp connection). Is this something
that can be done in VB Script? How can it be done? I already use the
following code which works to log the user off a non-terminal server
machine;

Set colOperatingSystems = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(Shutdown)}!\\localhost\root\cimv2").ExecQuery("Select
* from Win32_OperatingSystem")

For Each objOperatingSystem In colOperatingSystems
ObjOperatingSystem.Win32Shutdown(4)
Next

Is there a way to script the terminal server session logoff?
Thank you in advance for your advice and/or suggestions.
 
 
 

How do you log off a Terminal Server session user via WSH script?

Post by Marty Lis » Fri, 21 Jan 2005 14:49:29


One option is to execute LOGOFF.EXE (in the System32 folder).