Shoutbox

Shutdown script help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Shutdown script help (/showthread.php?tid=83912)

Shutdown script help by hello123456 on 05-24-2008 at 11:49 AM

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)
{
}

RE: Shutdown script help by foaly on 05-24-2008 at 11:52 AM

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 ){


RE: Shutdown script help by hello123456 on 05-24-2008 at 12:28 PM

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.


RE: Shutdown script help by foaly on 05-24-2008 at 12:36 PM

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.


RE: Shutdown script help by hello123456 on 05-24-2008 at 12:41 PM

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 :P The only problem is that remotely only !shutdown works.


RE: Shutdown script help by foaly on 05-24-2008 at 12:46 PM

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 :P 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...
RE: Shutdown script help by hello123456 on 05-24-2008 at 12:53 PM

Ok, they work now :) Thanks for helping Foaly :D


RE: Shutdown script help by linx05 on 05-25-2008 at 08:25 AM

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.