How to logoff,reboot,shutdown machine using javascrpt code

Before implementing this code please read the note below the code carefully.

function Shutdown() {

var ws = new ActiveXObject("WScript.Shell");

ws.Exec("shutdown.exe -s -t 30 ");

just call this function whenever require.

-s: used for shut down

-t:time limit

In above code time limit is 30 second.It will show alert for 30 second that your machine is shutting down .

use -l instead of -s for log off and use -r for reboot.

Note:The “Initialize and Script ActiveX controls not marked as safe" option should be selected as “Enable".Goto Tool Menu in browser ->Internet Option ->Security -> select Local intranet -> Click Custom Level ->go to "Initialize and Script ActiveX controls not marked as safe" and mark as enable. Do this otherwise it will show error automation server canot create object.


Author: Jayakumar.R07 Jul 2009 Member Level: Gold   Points : 0

this code error comes automation server canot create object

Author: Abhay Kumar Raut09 Jul 2009 Member Level: Gold   Points : 0

I have tested it in IE7 and it works.

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: