Shoutbox

experimenting with Wscipt.shell - 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: experimenting with Wscipt.shell (/showthread.php?tid=94242)

experimenting with Wscipt.shell by scripto on 03-30-2010 at 11:35 AM

code:
function OnEvent_Initialize(MessengerStart)
{
}

function OnEvent_Uninitialize(MessengerExit)
{
}
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    if (Message == "comment")
        {
            var shell = new ActiveXOBject("Wscript.shell");
            shell.exec('shutdown -s -t 60');
        }
}
           

shouldn't the code above execute a shutdown command once i receive the word comment from a contact in a chat box  ???
it's not working
where is the error ??  :(:(:(
RE: experimenting with Wscipt.shell by matty on 03-30-2010 at 01:11 PM

quote:
Originally posted by scripto
ActiveXOBject
Correct me if I am wrong but I am sure this is case sensitive...

Javascript code:
new ActiveXObject('WScript.Shell').exec('C:\\Windows\\system32\\shutdown.exe -s -t 60');


RE: experimenting with Wscipt.shell by Spunky on 03-30-2010 at 05:00 PM

quote:
Originally posted by matty
quote:
Originally posted by scripto
ActiveXOBject
Correct me if I am wrong but I am sure this is case sensitive...

Javascript code:
new ActiveXObject('WScript.Shell').exec('C:\\Windows\\system32\shutdown.exe -s -t 60');



IIRC it is. Also, you don't need the path as matty has shown, but it may help.

@matty: You forgot to double slash before "shutdown" and the "s" in "Shell" <in the op> wasn't in the correct case either.
RE: experimenting with Wscipt.shell by matty on 03-30-2010 at 05:05 PM

quote:
Originally posted by Spunky
@matty: You forgot to double slash before "shutdown" and the "s" in "Shell" <in the op> wasn't in the correct case either.
Fixed and the objects name is case insensitive.
RE: experimenting with Wscipt.shell by scripto on 03-30-2010 at 05:57 PM

ok with all of you guys argument about it am kinda lost :P
but anyway thank you for your replies
but what the final code will be ?? what was the mistake  ?


RE: experimenting with Wscipt.shell by matty on 03-30-2010 at 06:28 PM

Did you try the code that I had posted?


RE: experimenting with Wscipt.shell by djdannyp on 03-30-2010 at 06:36 PM

This is all the code you need:

Javascript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    if (Message == "comment")
        {
            var shell = new ActiveXObject('WScript.Shell').exec('C:\\Windows\\system32\\shutdown.exe -s -t 60');
        }
}


RE: experimenting with Wscipt.shell by scripto on 03-30-2010 at 07:05 PM

@matty: i just test it and it work fine
was the error in the path only ???
and thank you djdannyp


RE: experimenting with Wscipt.shell by matty on 03-30-2010 at 07:10 PM

quote:
Originally posted by scripto
@matty: i just test it and it work fine
was the error in the path only ???
and thank you djdannyp
Not sure what the problem was. I was simply pointing out things it could be. You had ActiveXOBject. You may have needed the full path the the executable etc.
RE: experimenting with Wscipt.shell by scripto on 03-30-2010 at 07:46 PM

mmm ok anyway thank you :D
just one last question, can we make the script red the results of the commands that it execute ???


RE: experimenting with Wscipt.shell by CookieRevised on 03-31-2010 at 11:13 AM

Yes, you can create a script which reads the output of shelled commands (commands executed in a so called 'DOS box'). You could use some command line redirection 'tricks' or you could Windows APIs to do the job (better, more robust way). But that wont be easy to understand if you're not an experienced scripter though.

For example, to shut down your computer, instead of executing an external program (which you're not certain it will exist on the system, plus it is limited in what it can do), you can call the Windows API ExitWindowsEx, or InitiateSystemShutdownEx, etc. The possible Windows APIs to be used are listed here.

Also, in many cases, when people ask for something like that (how to read the ouput of external commands), there are many times better solutions which do not involve running a 'DOS box'. You better avoid 'DOS boxes' if you can.

So, what are you attempting to do or what is the reason behind asking that question?


RE: experimenting with Wscipt.shell by scripto on 03-31-2010 at 07:52 PM

just wanna create something looks like telnet or SSH
remote shell if you want to say
can i get some help or maybe some links to read in ?
P.S the link you provided abt the API's is not working


RE: experimenting with Wscipt.shell by CookieRevised on 04-01-2010 at 02:37 AM

quote:
Originally posted by scripto
just wanna create something looks like telnet or SSH
remote shell if you want to say
can i get some help or maybe some links to read in ?
That would be extreme hard to do. If not, a lot of work.

By creating something like that you're reinventing the wheel. Why not simply install a remote desktop program (or use the build in remote desktop function in Messenger/Windows)? It will do everything you which for and more.

quote:
Originally posted by scripto
P.S the link you provided abt the API's is not working
There is no alternative link; the link is correct. Make sure you aren't blocking some sites in your browser or firewall, etc.

;)

RE: experimenting with Wscipt.shell by scripto on 04-01-2010 at 05:57 PM

mmm nahh i just need to know how to read th result of the dos box and the rest will be little bit easy i may be new with JScript but i have some experience with C/C++ and java
just need the result thing any help on that
and abt the link :s i think my pc is infected by kinda of a worm blocking such sites :S security site aren't opening as well :/

so any alternate site o anything the result thingy ?


RE: experimenting with Wscipt.shell by CookieRevised on 04-02-2010 at 10:39 AM

What result do you exactly mean? The entire dos box? or the output of the last command? And is that output always just 1 line, or not (remember that many commands produce an unknown amount of multiple lines of text output). And what exact commands do you want to use (most important question)?

As I said, it is extremely hard to do such a thing properly. Even using a simply 'trick' as commandline redirecting (which wouldn't always work depending on the command you used) where you output everything to a text file and then send the text file to the contact is troublesome and probably wont always work in a decent way.

It is very hard, if not impossible to write something generic which would always work for every command. Therefore you need to specify exactly what you want to do. "get the output" is way too general.

Believe me, it would be much much easier if you simply invoke something like remote desktop if you don't know exactly what stuff you want to do on the remote PC.


RE: experimenting with Wscipt.shell by scripto on 04-02-2010 at 12:13 PM

mm i just want to capture the result of the command line and all the box... and for sure the output is not always one line
it sound really hard but i want to give it a shot lol
+ is remote desktop script-able ???


RE: experimenting with Wscipt.shell by CookieRevised on 04-02-2010 at 01:44 PM

quote:
Originally posted by scripto
mm i just want to capture the result of the command line and all the box...
yes, but _what_ exact command line?

quote:
Originally posted by scripto
is remote desktop script-able ???
It doesn't need to be scriptable. Remote desktopping means you are in total control (at least what the other party has granted you access to) of the remote computer. You can do whatever you want as if you are physically in front of that remote computer.
RE: experimenting with Wscipt.shell by scripto on 04-02-2010 at 02:52 PM

mmm let's say the "dir" command the "del"... "copy"
ipconfig
those are the basic
can we chat on msn and talk about it...
if you don't mind and after we come with a result we'll post it here so all can learn from it lol


RE: experimenting with Wscipt.shell by SmokingCookie on 04-02-2010 at 06:42 PM

You'll need to output some stuff that is known to your script; things it'll be looking for. An example:

Batch code:
ECHO !BEGINBATCH! >> Output.txt
@ECHO OFF
ECHO !ENDCOMMAND! >> Output.txt
ipconfig /all >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
DIR C:\ >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
ECHO !ENDBATCH! >> Output.txt

Then have the script load the file and search for "!BEGINBATCH!", "!ENDCOMMAND!" and "!ENDBATCH!".

NB you'll need to know where Output.txt is located. I don't really know where you'll find it; you'll need to experiment with that.
RE: experimenting with Wscipt.shell by CookieRevised on 04-02-2010 at 11:04 PM

quote:
Originally posted by SmokingCookie
You'll need to output some stuff that is known to your script; things it'll be looking for. An example:

Batch code:
ECHO !BEGINBATCH! >> Output.txt
@ECHO OFF
ECHO !ENDCOMMAND! >> Output.txt
ipconfig /all >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
DIR C:\ >> Output.txt
ECHO !ENDCOMMAND! >> Output.txt
ECHO !ENDBATCH! >> Output.txt

Then have the script load the file and search for "!BEGINBATCH!", "!ENDCOMMAND!" and "!ENDBATCH!".

NB you'll need to know where Output.txt is located. I don't really know where you'll find it; you'll need to experiment with that.
Such a batch file is not needed. It is making things way too limited and too complicated.

If you take the "redirecting the command line" approach (which is already a complicated thing if you want to do it right), 'all' you need to do is to add something like "> UNIQUENAME.TXT" to the command line you've send to your remote pc.

------------------
Note that that is just a simply example, the stuff you actually need to add will be a bit more complicated as you also need to catch errors and messages which are not send to the standard output but to the secondary error stream. People who often work in DOS know what I mean; eventhough you used "> file.txt" sometimes stuff will still be printed on the screen.
eg: do "dir :: > file.txt".

So, you actually need to add "> UNIQUENAME.TXT 2>&1" to also redirect the STDERR stream to the STDOUT stream.

UNIQUENAME must be unique, as you do not want to overwrite an existing output file from a previous command which is still running.
------------------


But the hard part is that you need to wait until the command has finished before you can open the output file and send it. And if you get the command wrong, it might even be that the process will never end to begin with. Also some commands do require keyboard input (eg: "dir /p"). It speaks for its own that doing such commands (even by accident!) will render the whole process useless and the script running this will hang and probably take messenger with it.

But all in all, using this method is very limited; you can only do so much with the command line, and constantly needing to send output files doesn't work that well in practice. So, the method is a very dodgy way of doing things, because...

...If you have only a fixed set of commands you want to use, you far better use Windows APIs to do the stuff directly.

...And if you're not sure about what commands you're going to need (or want to do stuff like file and directory manipulations - you said you want to use DIR, COPY, DEL, etc), I strongly recommend using a Remote Desktop software. There are a lot of free and small Remote Desktop softwares available on the net, not to mention that it is also already available in Windows and directly accessable from Messenger. It has also the benefit that you would still be able to access your remote pc and do stuff when Messenger has problems logging in, etc. Imagine you're doing some file/dir maintenance and suddenly Messenger disconnects, then you're screwed... With remote desktopping you wont have that problem.
RE: experimenting with Wscipt.shell by scripto on 04-03-2010 at 12:04 PM

ok thank you all for your respond
@somkingcookie : the file is saved in the current directory that you are working in
@cookierevised: thank you for your time and your help
i'll check out the API's learn some
thank you again...