1

I'm looking for a way to run a cmd command without showing the cmd window to the user.

I'm using something like:

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

    }
    

But it still shows the window, is there anyway not to show it?

Thanks

Sandeep Bansal
  • 6,280
  • 17
  • 84
  • 126
  • 3
    So you want to shut down the users computer without them knowing, what a great idea! – Zifre Jan 17 '10 at 23:05
  • 3
    This is why we can't have nice things... or a bigger JavaScript sandbox. – Ryan Joy Jan 17 '10 at 23:06
  • I _hope_ that he's referring to a standalone WSH script, not a browser. – SLaks Jan 17 '10 at 23:08
  • @Zifre I just had an actual *laugh out loud* moment – alex Jan 17 '10 at 23:08
  • 1
    It was a request by a lot of users for a Shutdown Program I am making, this is used for a sidebar gadget so the user can do a timed shutdown from the sidebar – Sandeep Bansal Jan 17 '10 at 23:13
  • @Sandeep Bansal: sorry, I figured there probably were some valid uses, but I couldn't think of any at the time and your question didn't say why you wanted to do this. This is one of those questions where it's a good idea to be very clear about your intentions so you don't come across as malicious. Again, sorry. – Zifre Jan 17 '10 at 23:52

2 Answers2

6

Try using the Run function instead of Exec and pass it 0 as the second argument to prevent it showing the command prompt window:

ws.Run("shutdown.exe -r -t 120", 0);

The System Shutdown window will still be displayed (I don't think there is any way to suppress that).

Phil Ross
  • 25,590
  • 9
  • 67
  • 77
  • Like so C:\Windows\System32\mshta.exe "javascript:new ActiveXObject('WScript.Shell').Run('cmd /c start /max C:\\Windows\\Notepad.exe',0,false);close()" – Garric Apr 29 '21 at 00:59
1

You can make the window minimized using the following command:

cmd /c start /min SomeCommand

I assume that you're aware that this won't work in a browser, and I therefore assume that you're writing a standalone JScript file with WSH.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964