Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Scheduled Shutdown with cancel option

HI - I've been asked to deploy a script that runs once a week on a Friday evening, that shuts down any PCs left on by users in the office BUT it must warn them its happening and allow them to cancel if they are still working.

I thought this would be trivial but it appears not. The issue i have had is that any script i've tested (even when run as logged in user) seems to ignore my pop up prompts to allow cancel and just schedules the shutdown? Ive shoved an example vbscript script i was testing below but open to any alternatives if someone can assist?

There seem to be paid for solutions for this, but i cant believe it cant simply script this, rather than was 1k for someone else's code?!

 

--------shutdown.vbs----------

Option Explicit
Dim objShell, intShutdown
Dim strShutdown, strAbort

' -s = shutdown, -t 120 = 2 minutes, -f = force programs to close
strShutdown = "shutdown.exe -s -t 300 -f"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown, 0, false

'go to sleep so message box appears on top
WScript.Sleep 100

' Input Box to abort shutdown
intShutdown = (MsgBox("Your Computer will shutdown in 5 minutes. Do you want to cancel computer shutdown and continue working? If so then click the YES button. Please don't forget to shutdown when you have finished",vbYesNo+vbExclamation+vbApplicationModal,"Cancel Shutdown"))
If intShutdown = vbYes Then
' Abort Shutdown
strAbort = "shutdown.exe -a"
set objShell = CreateObject("WScript.Shell")
objShell.Run strAbort, 0, false
End if

Wscript.Quit

0

Comments

2 comments
Date Votes
  • For now, I've added a shortcut on the desktop of the user machines that point to a script to cancel shutdown , then added pop up messages to my pdq script to warn the shutdown is happening (10 mins before), then do the 10 min shutdown, then have for 9mins a pop up available to say if you want to cancel run the desktop script. 

    We'll see if it works, but it'd be great to make the cancel / add a delay that was a pop up too.

    0
  • Use the wshell.popup method. It has a built in timer. Once the timer expires it can automate the shutdown (shutdown doesn't get activated unless the user doesn't interact).

    VBScript - Popup Method (vbsedit.com)

    0