Windows 7 – Shutdown message with countdown and cancel

With such a heavy emphasis being placed on ‘green IT’ system administrators are now being asked to have all the company workstations shutdown at a set time. This can be achieved through various means including purchasing specalised products, but without offering the end user the ability to cancel or pause the shutdown you run the risk of a user still being at the computer when the shutdown begins or someone loosing work.

These HTA scripts are free and can be used to give a customised warning to users before their computers are automatically shutdown.

Shutdown HTA script – version 1

mb_shutdown

This version of Shutdown HTA features

  • A large cancel button and a 60 second countdown before the shutdown begins.
  • Improved countdown – now runs smoothly, says ‘minutes’ if there are 2 or more minutes remaining, says ‘minute’ if one minute remaining, and only says ‘seconds’ if in the last 60 second count down. A special thanks to Dave (see comments below) for helping improve the countdown.
  • When ran the window is placed on top of all open windows
  • When the 60 second count down sarts the window is placed on top of all open windows
  • plays a system beep when the HTA is ran
  • plays a system beep during the last 60 seconds of the count down

How to customise this script

  • change ‘var mins = 2.1;’ to the amount of minutes the countdown is required for
  • Change ‘<p><img src=”http://www.itsupportguides.com/templates/rt_afterburner_j15/images/mb_textimagelogo_grey.png” /></p>’  to point to your company logo, or delete
  • to remove the system beep, delete beep(); from line 131
  • to have the system RESTART (rather than shutdown) change ‘objSystem.Win32Shutdown 5’ to ‘objSystem.Win32Shutdown 6’

How to implement this script

Download using the link below.

Change ‘var mins = 2;’ for the amount of minutes you require the count down for.

Then run, or schedule when it needs to run using the Windows Task Scheduler (or your other third party application).

TIP: To implement this script you could have a copy on each workstation and have a local schedule call it, or you could create a server side script to psexec it on each workstation (calling the file from the server).

 

Need help adding the HTA application to a Windows 7 Scheduled Task? See: Windows 7 – Run Scheduled Task Interactively

 

Download

To use this script simply download using the link below and save it with an HTA extension.

 http://www.itsupportguides.com/downloads/Shutdown.hta
NOTE: Please note the HTML that calls an image (mb_textimagelogo_grey.png), this can be removed or changed to your company logo. I suggest you link it to an image which is available through http.

 

TIP: You may need to right-click and select ‘save link as’ to download this file.

Win7-ShutdownNote1

 

Shutdown HTA script – version 2

Special thanks to Chris (see comments below) for this version of the shutdown HTA script.

ShutdownHTA2

This version does all above with the addition of being able to:

  • Delay for 24 hours
  • Delay for 15 minutes
  • Delay for 30 minutes
  • Delay for 60 minutes

As well as a different look and feel to the GUI.

Download

www.itsupportguides.com/downloads/ShutdownWithDelay.hta

Looking for or have an improvement?

Leave a comment below if you’re looking for or have an improvement.

Related Articles

70 comments on “Windows 7 – Shutdown message with countdown and cancel

  1. Hi

    I would like to shutdown our company’s computers at a set time however allowing a user to cancel if they press the cancel button. Version 1 of the shutdown.hta script is exactly what I require (thank you to the creator) and I have set the timer to 30 minutes. On the server, I use a scheduled psexec task to run shutdown.hta on the remote computers I want to shutdown – This is all working fine.

    However, I have a problem where the script runs on computers that have no one logged into them but then if when a user logs on to the computer before the timer ends, the computer is shutdown as originally planned when the timer reaches zero.

    Take the following scenario:

    18:00 – Shutdown.hta is ran on computer (via psexec from the server). 30 minute shutdown timer starts.

    18:10 – User John Smith comes along and sits down at said computer. Logs in.

    18:30 – Shutdown.hta timer reaches zero and the computer automatically shuts down without prior warning to John Smith

    18:31 – John Smith is furious and calls the IT Department about losing the spreadsheet he was working on.

    Now the solution for the problem is simple as Chris has already overcome it with his scripts – If there is no user logged into the computer then shutdown immediately.

    My plan is very similar to Chris except not as complicated (as I don’t require to check Power Plans, AD groups or registry settings like he does. I will use two scheduled tasks on the server, both using psexec to execute the commands remotely to my workstations:

    Task A, 18:00 – Launch vbs script to shutdown any computers which are logged off.

    Task B, 18:01 – Launch shutdown.hta with a 30 minute timer on the (remaining) computers to alert the users that they’re computer will shutdown if they dont cancel.

    I am not very good with visual basic so don’t quite understand how to modify Chris’s script to suit my needs. I require the SchTskShudownCmptr.vbs only script I believe to only check if a user is logged in or not. If the outcome is yes then exit. If no, shutdown immediately. I am unsure how to delete all the other stuff from his script.

    Could somebody please help me with the vbs code I require to achieve what I want to do?

    Thanks,

    fraser.

  2. Looking at the .hta file it looks like a possibility – could this be used to, for example, run a .bat rather than shut down? Of course, after the script installs what it needs to it would include a reboot. Seems like where it calls shutdown it could be used to launch anything else. I don’t mind working at it, don’t expect it to be written out… possible?

    1. I would call an exe created for a bat to exe convertor the bat file

      call \scriptsshutdown.vbs
      that calls the vbscript below

      Const SHOW_ACTIVE_APP = 1

      Set objShell = Wscript.CreateObject(“Wscript.Shell”)

      objShell.Run (“\scriptsshutdown.hta”), SHOW_ACTIVE_APP, True

      Wscript.Quit
      It’s three separate files I know but it works

  3. Same here with the error – the first version shuts down fine so i’ve tried comparing the last bit of the script that initiates the shutdown but can’t see anything obvious missing or different….. Would love to get this working – useful little tool !

  4. Is it possible to ad a feature. Only allow The delay button to be pressed a fixed number of times, after this the delay buttons do not appear on the screen, or the buttons do nothing.
    Thanks
    Ringo

Leave a Reply

Your email address will not be published.