windowsbatch-filevbscriptsystem-shutdown

Windows 7 shutdown with hidden message box


Windows 7
simple .bat and .vbs files
level: bloody beginner
summary: suppress windows shutdown message box during "shutdown.exe"-call

I'm trying to run a simple system shutdown that is also clearing my temp files and providing an option to abort. Until now I almost reached my goal using some simple files getting called on after the other.

clear temp data

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

execute shutdown

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

then I'm creating a message box allowing me to abort shutdown by pressing the OK-button:

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 simply is shutdown /a)

The system is shutting down properly and the abort works, too. The issue is that Windows 7 is showing me an additional message box saying sth like "Windows will be shut down in less than 1 minute".

As a result I have 2 message boxes on my screen but I only want see my customized box from the .vbs file. At least I managed to move my custom box to the front... I also tried the so-called silent WshShell.Run and Set WshShell = Nothing workaround with no success. The message box still keeps popping up.

How can I suppress this box completely?


Solution

  • I'd use a slightly different approach:

    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