8

我正在尝试找到一种强制 Windows 重新启动的方法,但我遇到了问题。我试过了

Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _
     & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_
     & "Primary=true")
for each OpSys in OpSysSet
    retVal = OpSys.Reboot()
next

我也尝试过使用该shutdown -f -r命令,在这两种情况下,我有时都没有得到响应,如果我再试一次,我会收到一条错误消息,说“操作无法完成,因为系统正在关闭”,即使我离开它多久它不会关闭,它仍然允许我启动新程序,并且执行shutdown -a同样的错误。如何使用脚本强制 Windows 重新启动?

4

5 回答 5

10

尝试更换:

retVal = OpSys.Reboot()

和:

retVal = OpSys.Win32Shutdown(6)
于 2008-10-09T19:32:47.070 回答
4

好吧,这使用了 VBScript——尽管它确实调用了与您尝试执行的相同的命令行关闭。我已经对其进行了测试,并且可以正常工作。

Dim oShell 
Set oShell = CreateObject("WScript.Shell")

'restart, wait 5 seconds, force running apps to close
oShell.Run "%comspec% /c shutdown /r /t 5 /f", , TRUE

你运行的是什么操作系统?这个测试是针对 XP 的。我想知道服务器操作系统是否需要关闭代码...

于 2008-10-09T19:23:31.987 回答
3

您还可以尝试 Sysinternals now Microsoft 的 psShutdown 命令行实用程序。 http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx

于 2008-10-10T03:45:59.193 回答
2
'*********************************************************

Option Explicit

Dim objShell

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

'*********************************************************

这个小脚本会在 0 秒后重新启动本地计算机。

于 2011-06-08T02:29:16.953 回答
0
Set Reset= WScript.CreateObject ("WScript.Shell")

Reset.run "shutdown -r -t 00", 0, True

或者..

Shell "shutdown -r -t 00"   ' for restart

Shell "shutdown -s -t 00"  ' for Shutdown

Shell "shutdown -l -t 00"   ' for log off

Shell "shutdown -a -t 00"  ' for abort
于 2019-04-11T10:28:34.867 回答