我正试图找到一种方法来强制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重新启动?
尝试更换:
retVal = OpSys.Reboot()
附:
retVal = OpSys.Win32Shutdown(6)
好吧,这使用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的。我想知道服务器操作系统是否需要关机代码......
您也可以从Sysinternals现在的Microsoft尝试psShutdown命令行实用程序。 http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx
'*********************************************************
Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
'*********************************************************
这个小脚本在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