Reputation: 1709
I'm using a VBScript to run an application on my Win Server 2003, and I want it to log the user off after a set amount of time. Something along the lines of:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set OExe = WshShell.exec("somecommand.exe")
WScript.Sleep 1000000
OExe.Terminate
<Insert LogOff code>
Upvotes: 1
Views: 19178
Reputation: 9368
Example using WMI:
Set oSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each oSystem in oSystems
'LOGOFF = 0
'SHUTDOWN = 1
'REBOOT = 2
'FORCE = 4
'POWEROFF = 8
oSystem.Win32Shutdown 0
Next
Upvotes: 0
Reputation: 1305
Wscript.Sleep(100000)
SET wshell = Wscript.CreateObject("Wscript.Shell")
wshell.exec("shutdown.exe -L -F")
Just tested this on a w7 box, seems to work alright.
Upvotes: 2
Reputation: 32596
Something like
WshShell.Run "C:\windows\system32\shutdown.exe /l", 0, false
should do the trick
Upvotes: 2