?
Solved

JavaScript ActiveXObject using WScript.shell to run shutdown.exe command

Posted on 2005-04-28
1
Medium Priority
?
6,191 Views
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:

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

}
</script>

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.
0
Comment
Question by:Shank1
1 Comment
 
LVL 7

Accepted Solution

by:
TheMCSE earned 500 total points
ID: 13890695
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\"");

}
</script>

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"');

}
</script>

Good luck!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

850 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