none
Script - Shutdown machines with messagebox to abort the shutdown RRS feed

  • Question

  • Hi folks,

    I need a script that shuts down all the computers in my environment. However, this script must have a button to abort the shutdown in the course. I'll deploy this script in a GPO.

    Thank you.

    Thursday, July 30, 2020 1:00 PM

Answers

  • Hi All,

    I managed to it. Here's the script:

    Option Explicit
     Dim objShell, intShutdown
     Dim strShutdown, strAbort

     ' -s = shutdown, -t 30 = 10 Segundos, -f = force programs to close
     strShutdown = "shutdown.exe -r -t 30 -f"
     set objShell = CreateObject("WScript.Shell")
     objShell.Run strShutdown, 0, false

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

     ' Input Box to abort shutdown
     intShutdown = (MsgBox("YOUR COMPUTER WILL SHUTDWOWN LESS THAN 1 MINUTE. DO YOU WANT TO ABORT IT?",vbYesNo+vbExclamation+vbApplicationModal,"AUTOMATIC 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

    enjoy it.

    • Marked as answer by Windows Man Wednesday, August 5, 2020 6:52 PM
    Wednesday, August 5, 2020 6:51 PM

All replies

  • Hi Man :)

    great idea, go ahead 👍


    The opinion expressed by me is not an official position of Microsoft

    Thursday, July 30, 2020 1:23 PM
  • My bad guys...I didn't realize it...

    :(

    Thursday, July 30, 2020 4:24 PM
  • Please, where am I able to post script questions? I need this script...

    Thank you.

    Friday, July 31, 2020 2:19 PM
  • You can find someone on: upwork.com or freelancer.com or any other freelance platform

    Also you can try to write it by yourself, then we can try help you if you will find any problems :) (in this case you need spend some tile to read\test\etc)

    The opinion expressed by me is not an official position of Microsoft

    Friday, July 31, 2020 2:42 PM
  • Please, where am I able to post script questions? I need this script...

    Thank you.

    What you are asking cannot b e done. l You cannot display a message box during shutdown as there is no session to display it in.  A message box would hang the system.


    \_(ツ)_/

    Friday, July 31, 2020 6:07 PM
  • Why do you need a script? Just use the /t switch on shutdown.exe to give the desktop user a timeframe where they can abort the shutdown.

    C:\>shutdown /?
    Usage: shutdown [/i | /l | /s | /sg | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/soft] [/fw] [/f]
        [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

        No args    Display help. This is the same as typing /?.
        /?         Display help. This is the same as not typing any options.
        /i         Display the graphical user interface (GUI).
                   This must be the first option.
        /l         Log off. This cannot be used with /m or /d options.
        /s         Shutdown the computer.
        /sg        Shutdown the computer. On the next boot, if Automatic Restart Sign-On
                   is enabled, automatically sign in and lock last interactive user.
                   After sign in, restart any registered applications.
        /r         Full shutdown and restart the computer.
        /g         Full shutdown and restart the computer. After the system is rebooted,
                   if Automatic Restart Sign-On is enabled, automatically sign in and
                   lock last interactive user.
                   After sign in, restart any registered applications.
        /a         Abort a system shutdown.
                   This can only be used during the time-out period.
                   Combine with /fw to clear any pending boots to firmware.
        /p         Turn off the local computer with no time-out or warning.
                   Can be used with /d and /f options.
        /h         Hibernate the local computer.
                   Can be used with the /f option.
        /hybrid    Performs a shutdown of the computer and prepares it for fast startup.
                   Must be used with /s option.
        /fw        Combine with a shutdown option to cause the next boot to go to the
                   firmware user interface.
        /e         Document the reason for an unexpected shutdown of a computer.
        /o         Go to the advanced boot options menu and restart the computer.
                   Must be used with /r option.
        /m \\computer Specify the target computer.
        /t xxx     Set the time-out period before shutdown to xxx seconds.
                   The valid range is 0-315360000 (10 years), with a default of 30.
                   If the timeout period is greater than 0, the /f parameter is
                   implied.


    • Edited by MotoX80 Tuesday, August 4, 2020 4:15 PM
    Tuesday, August 4, 2020 4:14 PM
  • Hi All,

    I managed to it. Here's the script:

    Option Explicit
     Dim objShell, intShutdown
     Dim strShutdown, strAbort

     ' -s = shutdown, -t 30 = 10 Segundos, -f = force programs to close
     strShutdown = "shutdown.exe -r -t 30 -f"
     set objShell = CreateObject("WScript.Shell")
     objShell.Run strShutdown, 0, false

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

     ' Input Box to abort shutdown
     intShutdown = (MsgBox("YOUR COMPUTER WILL SHUTDWOWN LESS THAN 1 MINUTE. DO YOU WANT TO ABORT IT?",vbYesNo+vbExclamation+vbApplicationModal,"AUTOMATIC 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

    enjoy it.

    • Marked as answer by Windows Man Wednesday, August 5, 2020 6:52 PM
    Wednesday, August 5, 2020 6:51 PM
  • My guess is that this will work only if run in the user's context. If you run it from a different user context, my guess is the user will never see the dialog box. I would definitely test running it as a separate user before deploying it as a solution.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, August 5, 2020 9:49 PM
    Moderator
  • To add to Bill's warning.  This can only be rn from a GPO as a logon, logoff script.  That will require a user to logon or logoff to execute teh script.  If run as a "Shutdown" script it will just hang.

    It can be run as a scheduled task that will execute in the current users session assuming the user has a session but this wil only execute at logon or at a specific time.

    There is no way to remotely execute a shutdown and prompt the user.  The prompt will only be displayed remotely.

    The OP provides no clear reason for doing this.  The reason (USE Case) is the determining factor that tells us how this might be done if it is possible.

    There are third party tools which can do what is suggested or wee can create a service that will allow us to do this.  There are other methods that can do this but all require installing something on the user's machine.


    \_(ツ)_/

    Wednesday, August 5, 2020 10:05 PM