1

Windows 7
简单的 .bat 和 .vbs 文件
级别:血腥初学者
总结:在“shutdown.exe”调用期间抑制 Windows 关闭消息框

我正在尝试运行一个简单的系统关闭,它也清除了我的临时文件并提供了一个中止选项。到目前为止,我几乎达到了我的目标,使用一些简单的文件被一个接一个地调用。

清除临时数据

rmdir /s /q "C:\Users\myusername\AppData\Local\Temp"

执行关机

c:\windows\system32\shutdown -s -f -t 30

然后我正在创建一个消息框,允许我通过按 OK 按钮中止关机:

x=msgbox ("Temp files cleared. Executing system shutdown now!" & vbNewLine & "Press OK to abort shutdown.",262144+48+0, "System Shutdown")

If x=vbOk Then
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "abortShutdown.bat"
end if

(abortShutdown.bat 简直就是shutdown /a

系统正在正常关闭,并且中止也有效。问题是 Windows 7 向我显示了一个额外的消息框,上面写着“Windows 将在不到 1 分钟的时间内关闭”。

结果,我的屏幕上有 2 个消息框,但我只想从 .vbs 文件中查看我的自定义框。至少我设法将我的自定义框移到了前面......我还尝试了所谓的静默 WshShell.RunSet WshShell = Nothing解决方法,但没有成功。消息框仍然不断弹出。

我怎样才能完全压制这个盒子?

4

1 回答 1

1

我会使用稍微不同的方法:

timeout = 30 'seconds

Set sh = CreateObject("WScript.Shell")

x = sh.Popup("Temp files cleared. Shutting down in " & timeout & " seconds!" & _
      vbNewLine & "Press OK to shutdown immediately." & vbNewLine & _
      "Press Cancel to abort shutdown.", timeout, "System Shutdown", vbOKCancel)

If x = vbCancel Then
  sh.Run "shutdown -a"
Else
  sh.Run "shutdown -s -f -t 0"
End If
于 2014-11-12T11:37:15.123 回答