VB script to shutdown computer...

Posted on 2012-09-12
Last Modified: 2012-09-15
I'd like help on writing a vb script that will shutdown computer but also give the option to the user to cancel the shutdown and if there is no response within a few minutes then the computer will shut down. I am planing to schedule this script to run at a certain time.

Thanks in advance.
Question by:begeorge
    LVL 17

    Accepted Solution

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Exec("shutdown /s /t 100 /c ""shutdown /a to abort""")

    Open in new window

    where 100 is time in seconds.

    Author Comment

    Thanks a lot for the quick answer. I need to display a message like "your computer will shutdown in 2 min...."

    Author Comment

    I found out how to change message but the computer shuts down even if I click close. I need a way for them to cancel the shutdown. Also is there a way to play a sound to alert them of the message? Thanks
    LVL 17

    Expert Comment

    Say more about the situation. What will trigger the script? Will it run in the user's session or some other (service?) session?

    We need to separate this into:
     a conversation with the user
     followed by (as appropriate) the shutdown command.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
    Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now