What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Shutdown script help

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
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
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
Profile E-Mail PM Find Quote Report
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
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
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
Profile E-Mail PM Find Quote Report
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 :P The only problem is that remotely only !shutdown works.
05-24-2008 12:41 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
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 :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...
05-24-2008 12:46 PM
Profile E-Mail PM Find Quote Report
hello123456
New Member
*


Posts: 6
Joined: May 2008
O.P. RE: Shutdown script help
Ok, they work now :) Thanks for helping Foaly :D
05-24-2008 12:53 PM
Profile E-Mail PM Find Quote Report
linx05
Senior Member
****

Avatar
Charlie!!!

Posts: 973
Reputation: 25
38 / Other / Flag
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.
For news on anything Tremors, visit Tremors News
End Darko
My blog about my film


Scripts I want to get made:
Taskbar icon to change when contact is typing
05-25-2008 08:25 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On