JavaScript ActiveXObject using to run shutdown.exe command

Posted on 2005-04-28
Last Modified: 2008-02-01
I am trying to write a function using Java Script that utilizes an Active X control to shutdown a windows box.  The plan is to imbed this webpage as part of the active desktops on some windows lab machines so users will reboot when they are done with a machine.  Here is my code that I am having problems with:

function reboot()  {
      var ws = new ActiveXObject("WScript.Shell");
      ws.Exec("shutdown.exe -r -t 30 -f -c Testing_Testing");


I basically want the users to see a little message when this function gets called by the button on the desktop.  I am having problems with the -c switch of the shutdown command.  I want to be able to write the message without the _ between each of the words.  Is there a way that I can type a message without the _ between each word?  I have tried using single quotes ' ' and brackets [] around the message and neither have worked.
Question by:Shank1
    1 Comment
    LVL 7

    Accepted Solution

    Did you try escaping the quote (\")?  In VBS, this could be done easily by wrapping the quoted string in Chr(34)'s or adding an extra double quote.

    <SCRIPT LANGUAGE="JavaScript">
    function reboot()  {
         var ws = new ActiveXObject("WScript.Shell");
         ws.Exec("shutdown.exe -r -t 30 -f -c \"Testing Testing\"");


    I thought this would also work by converting your existing double quotes to single quotes, and then using the double quotes in context:

    <SCRIPT LANGUAGE="JavaScript">
    function reboot()  {
         var ws = new ActiveXObject('WScript.Shell');
         ws.Exec('shutdown.exe -r -t 30 -f -c "Testing Testing"');


    Good luck!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now