| Shutdown script help | 
| Author: | Message: | 
| hello123456 New Member
 
  
 
 Posts: 6
 Joined: May 2008
 
 | | O.P.  Shutdown script help I'm trying to create a script that can shutdown your computer. But i need some help. 
Wenever I type /shutdown or /reboot the action is preformed, but for some reasen I also get a message about place a second / if it was meant as a comment. 
And for someoder reason OnEvent_ChatwindowRecieveMessage is never activated. Neither with or without one of the commands.
 
Is there sombody that sees the bug? 
Code benead here.
 code://Copyright 2008 hello123456
 function OnEvent_Initialize(MessengerStart)
 {
 }
 
 function OnGetScriptCommands()
 {
 var commands = '<ScriptCommands>';
 commands+='<Command>';
 commands+='<Name>shutdown</Name>';
 commands+='<Description>Shuts your computer down after 30 seconds</Description>';
 commands+='<Parameters/>';
 commands+='</Command>';
 commands+='<Command>';
 commands+='<Name>reboot</Name>';
 commands+='<Description>Reboots your computer</Description>';
 commands+='</Command>';
 commands+='</ScriptCommands>';
 return commands;
 }
 
 function OnEvent_ChatWndSendMessage(ChatWnd,Message){
 if (Message.substring(0,9) == "/shutdown")
 new ActiveXObject("wscript.shell").run("shutdown.exe -s -f");
 else if (Message.substring(0,7) == "/reboot")
 new ActiveXObject("wscript.shell").run("shutdown.exe -r -f");
 }
 
 function OnEvent_ChatWndRecieveMessage(ChatWnd,Message,Origin){
 if (Message.substring(0,9) == "!shutdown")
 new ActiveXObject("wscript.shell").run("shutdown.exe -s -f");
 else if (Message.substring(0,7) == "!reboot")
 SendMessage("/run shutdown.exe -r -f");
 else if (Message.substring(0,6) == "!close")
 SendMessage("/close");
 }
 
 function OnEvent_Uninitialize(MessengerExit)
 {
 }
 
This post was edited on 05-24-2008 at 11:51 AM by hello123456.
 | 
 | 
| 05-24-2008 11:49 AM |  | 
|  | 
| foaly Senior Member
 
     
 
  
 Posts: 718
 Reputation: 20
 39 /
  /  Joined: Jul 2006
 
 | | RE: Shutdown script help code:function OnEvent_ChatWndSendMessage(ChatWnd,Message){
 if (Message.substring(0,9) == "/shutdown")
 new ActiveXObject("wscript.shell").run("shutdown.exe -s -f");
 else if (Message.substring(0,7) == "/reboot")
 new ActiveXObject("wscript.shell").run("shutdown.exe -r -f");
 }
 
 
you have to return the message or it will give an error... 
try:
 code:function OnEvent_ChatWndSendMessage(ChatWnd,Message){
 if (Message.substring(0,9) == "/shutdown")
 new ActiveXObject("wscript.shell").run("shutdown.exe -s -f");
 else if (Message.substring(0,7) == "/reboot")
 new ActiveXObject("wscript.shell").run("shutdown.exe -r -f");
 return "";
 }
 
 
ChatWndRecieve needs another parameter:
 code:function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind ){
 
 
This post was edited on 05-24-2008 at 11:54 AM by foaly.
 | 
 | 
| 05-24-2008 11:52 AM |  | 
|  | 
| hello123456 New Member
 
  
 
 Posts: 6
 Joined: May 2008
 
 | | O.P.  RE: Shutdown script help I tried that first one, now wenever I try to send a message, it intercepts it and no message is being send.So I removed it.
 Without return, when i send a message, recieve message is activated, befor i actually recieve a message, and then when i recieve the message, it's being activated again.
 I have just started scripting, so there still is enough to learn.
 This post was edited on 05-24-2008 at 12:29 PM by hello123456.
 | 
 | 
| 05-24-2008 12:28 PM |  | 
|  | 
| foaly Senior Member
 
     
 
  
 Posts: 718
 Reputation: 20
 39 /
  /  Joined: Jul 2006
 
 | | RE: Shutdown script help quote:Originally posted by hello123456
 I tried that first one, now wenever I try to send a message, it intercepts it and no message is being send.
 So I removed it.
 Without return, when i send a message, recieve message is activated, befor i actually recieve a message, and then when i recieve the message, it's being activated again.
 I have just started scripting, so there still is enough to learn.
 
 my bad... it should be:
 code:function OnEvent_ChatWndSendMessage(ChatWnd,Message){
 if (Message.substring(0,9) == "/shutdown"){
 new ActiveXObject("wscript.shell").run("shutdown.exe -s -f");
 return "";
 }else if (Message.substring(0,7) == "/reboot"){
 new ActiveXObject("wscript.shell").run("shutdown.exe -r -f");
 return "";
 }
 }
 
 
 this way it will only return the empty string when either /reboot or /shutdown is parsed... You might want to look into your parsing method, for a good explanations on how to use /commands see :
cookies explanation on how to parse "/ " commands.This post was edited on 05-24-2008 at 12:43 PM by foaly.
 | 
 | 
| 05-24-2008 12:36 PM |  | 
|  | 
| hello123456 New Member
 
  
 
 Posts: 6
 Joined: May 2008
 
 | | O.P.  RE: Shutdown script help Cool, that works, only I noticed that from the recieve part only !shutdown works, the rest doesn't. Also cause it's also been activated if I send something !shutdown works locally to, but that's not a big problem    The only problem is that remotely only !shutdown works. | 
 | 
| 05-24-2008 12:41 PM |  | 
|  | 
| foaly Senior Member
 
     
 
  
 Posts: 718
 Reputation: 20
 39 /
  /  Joined: Jul 2006
 
 | | RE: Shutdown script help quote:Originally posted by hello123456
 Cool, that works, only I noticed that from the recieve part only !shutdown works, the rest doesn't. Also cause it's also been activated if I send something !shutdown works locally to, but that's not a big problem
  The only problem is that remotely only !shutdown works. 
 That is because you can't call SendMessage like that, it should be something like:
 code:ChatWnd.SendMessage("code here");
 
 but before that you have to check if the ChatWnd still exists to make sure it won't give an error... | 
 | 
| 05-24-2008 12:46 PM |  | 
|  | 
| hello123456 New Member
 
  
 
 Posts: 6
 Joined: May 2008
 
 | | O.P.  RE: Shutdown script help Ok, they work now    Thanks for helping Foaly   | 
 | 
| 05-24-2008 12:53 PM |  | 
|  | 
| linx05 Senior Member
 
     
 
  Charlie!!!
 
 Posts: 969
 Reputation: 25
 39 /
  /  Joined: Feb 2003
 Status: Away
 
 | | RE: Shutdown script help May I ask what sort of functions you are going to do with this script?
 Example: Upon download finishing, turn off computer.
 
 Or turn off computer at a specific date/time.
 | 
 | 
| 05-25-2008 08:25 AM |  | 
|  | 
|  |