windows 如何从 vbscript 注销?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3938575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:24:59  来源:igfitidea点击:

How do I logout from vbscript?

windowsvbscriptlogoff

提问by tzenes

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:

我正在使用 VBScript 在我的 Win Server 2003 上运行一个应用程序,我希望它在设定的时间后注销用户。类似的东西:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set OExe = WshShell.exec("somecommand.exe")
WScript.Sleep 1000000
OExe.Terminate
<Insert LogOff code>

回答by Andrew Cooper

Something like

就像是

WshShell.Run "C:\windows\system32\shutdown.exe /l", 0, false

should do the trick

应该做的伎俩

回答by Pete

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.

刚刚在 w7 盒子上测试了这个,似乎工作正常。

回答by wsware

Example using WMI:

使用 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