我正在使用 VBScript 在我的 Win Server 2003 上运行应用程序,我希望它在一段时间后将用户注销。类似于以下内容:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set OExe = WshShell.exec("somecommand.exe")
WScript.Sleep 1000000
OExe.Terminate
<Insert LogOff code>
就像是
WshShell.Run "C:\windows\system32\shutdown.exe /l", 0, false
应该做的伎俩
Wscript.Sleep(100000)
SET wshell = Wscript.CreateObject("Wscript.Shell")
wshell.exec("shutdown.exe -L -F")
刚刚在 w7 盒子上测试了这个,似乎工作正常。
使用 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