我正试图找到一种强制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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top