Shoutbox

[question] Run commands from script - 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: [question] Run commands from script (/showthread.php?tid=66092)

[question] Run commands from script by skorpan on 09-11-2006 at 10:58 AM

Hi!

I have searched the forum for a way to run commands from the scripts.

If I want to open the folder c:\test\, or the file c:\program.exe, how do I do that?


RE: Run commands from script by Felu on 09-11-2006 at 11:00 AM

code:
var Shell = new ActiveXObject('WScript.Shell');
Shell.Run("c:\\program.exe");//You need to use "\\" instead of "\"


RE: RE: Run commands from script by skorpan on 09-11-2006 at 11:12 AM

quote:
Originally posted by -!Felu!-
code:
var Shell = new ActiveXObject('WScript.Shell');
Shell.Run("c:\\program.exe");//You need to use "\\" instead of "\"



Thanks alot!
Now I only need to know how I replace single "\" with "\\" in strings.. ;)
RE: [question] Run commands from script by Felu on 09-11-2006 at 11:16 AM

quote:
Originally posted by skorpan
Thanks alot!
Now I only need to know how I replaces single "\" with "\\" in strings.. [Image: msn_wink.gif]
I meant in scripting you'll need to use double slash(\\) instead of a single slash(\) in any path you specify.
RE: RE: [question] Run commands from script by skorpan on 09-11-2006 at 11:17 AM

quote:
Originally posted by -!Felu!-
quote:
Originally posted by skorpan
Thanks alot!
Now I only need to know how I replaces single "\" with "\\" in strings.. [Image: msn_wink.gif]
I meant in scripting you'll need to use double slash(\\) instead of a single slash(\) in any path you specify.

I got that =)
But the functions in Messenger Plus scripting enviroment returns path in the style of "c:\my dp folder\", so I need to change it to "c:\\my dp folder\\".

That is my new problem :)
RE: [question] Run commands from script by Felu on 09-11-2006 at 11:22 AM

quote:
Originally posted by skorpan
I got that =)
But the functions in Messenger Plus scripting enviroment returns path in the style of "c:\my dp folder\", so I need to change it to "c:\\my dp folder\\".

That is my new problem (Smilie)
No, it returns the correct way... If it returns "c:\\my dp folder\\" the folder won't open but if it returns "c:\my dp folder\" the folder would open.

I don't know the reason behind this, but i think you get what i mean. If someone can explain why then please do [Image: msn_tongue.gif].
RE: RE: [question] Run commands from script by skorpan on 09-11-2006 at 11:26 AM

quote:
Originally posted by -!Felu!-
quote:
Originally posted by skorpan
I got that =)
But the functions in Messenger Plus scripting enviroment returns path in the style of "c:\my dp folder\", so I need to change it to "c:\\my dp folder\\".

That is my new problem (Smilie)
No, it returns the correct way... If it returns "c:\\my dp folder\\" the folder won't open but if it returns "c:\my dp folder\" the folder would open.
Wrong.
The function in Messenger Plus I use returns a value in style of "c:\my folder\sub folder" (I add a "\" on the end manually).

If I take this string and pass it on to Shell.Run(string); (where string is the returned path from above) it dies not open anytning. I just get a error message.
RE: RE: [question] Run commands from script by alexp2_ad on 09-11-2006 at 11:26 AM

EDIT:  What's the error you get, and what's the exact code you're using?

quote:
Originally posted by -!Felu!-
I don't know the reason behind this, but i think you get what i mean. If someone can explain why then please do [Image: msn_tongue.gif].

The reason is that in strings, the backslash \ is used as an "escape character", meaning it's used to show that the next character signifies something other than it's literal character.  For example:

\n  =  new line
\"   =   inside a string this is used to show a quote, rather than actually showing the ending of the string

So to get an actual \ into a string, you double it up to \\ and it gets changed into a \ when the string is passed / used etc.
RE: RE: RE: [question] Run commands from script by skorpan on 09-11-2006 at 11:34 AM

quote:
Originally posted by alexp2_ad
So to get an actual \ into a string, you double it up to \\ and it gets changed into a \ when the string is passed / used etc.

I wrote this above...
quote:
But the functions in Messenger Plus scripting enviroment returns path in the style of "c:\my dp folder\", so I need to change it to "c:\\my dp folder\\".

I ask again: How do I double it up in a string?
RE: [question] Run commands from script by alexp2_ad on 09-11-2006 at 11:36 AM

You actually WANT a double \\ for some reason?

Use a quadruple one:

"c:\\\\my dp folder\\\\"

That will be seen as "c:\\my dp folder\\"


RE: [question] Run commands from script by Spunky on 09-11-2006 at 11:39 AM

Can you not just use

code:
strPath = strPath.replace("\\","\\\\");


where strPath is the variable containing the path?

EDIT: Damn, beaten to it again :p
RE: RE: [question] Run commands from script by skorpan on 09-11-2006 at 11:42 AM

quote:
Originally posted by alexp2_ad
You actually WANT a double \\ for some reason?
...
code:
Messenger.ReceiveFileDir
Returns something like: c:\my documents\my recieved files, right?
This is stored in a string.

Before I can use it with
code:
Shell.Run
I need to change it into: c:\\my documents\\my recieved files.

How do I do that?
RE: [question] Run commands from script by Spunky on 09-11-2006 at 11:44 AM

code:
strPath = Messenger.ReceiveFileDir;
strPath = strPath.replacE("\\","\\\\");
Shell.Run(strPath);


That should do it. :p
RE: RE: [question] Run commands from script by skorpan on 09-11-2006 at 11:48 AM

quote:
Originally posted by SpunkyLoveMuff
Can you not just use
code:
strPath = strPath.replace("\\","\\\\");


where strPath is the variable containing the path?

EDIT: Damn, beaten to it again :p

Thanks alot! =)
I solved it myself just before i read this :P But you actually did come with help that was useful =)
RE: [question] Run commands from script by Spunky on 09-11-2006 at 11:49 AM

Hey no problem, although credit should probably goto Alexp2_ad as he got there faster than me :p

EDIT: My spelling is getting worse :s


RE: RE: [question] Run commands from script by alexp2_ad on 09-11-2006 at 11:51 AM

quote:
Originally posted by SpunkyLoveMuff
Hey no problem, although credit should probably goto Alexp2_ad as he got therte faster than me :p


And because you posted a triple backslash first didn't you? :P

BTW, can anyone get this to work, I tried:

new ActiveXObject('WScript.Shell').run(Messenger.ReceiveFileDir);

But it returns an unknown error, it should work as is, but it doesn't, tried replacing \ or whatever, but it didn't help. :S
RE: [question] Run commands from script by Felu on 09-11-2006 at 12:18 PM

quote:
Originally posted by alexp2_ad
new ActiveXObject('WScript.Shell').run(Messenger.ReceiveFileDir);
code:
new ActiveXObject('WScript.Shell').run(Messenger.ReceivedFileDir);
Should Work :p
RE: [question] Run commands from script by markee on 09-11-2006 at 12:19 PM

quote:
Originally posted by alexp2_ad
BTW, can anyone get this to work, I tried:

new ActiveXObject('WScript.Shell').run(Messenger.ReceiveFileDir);

But it returns an unknown error, it should work as is, but it doesn't, tried replacing \ or whatever, but it didn't help. [Image: msn_confused.gif]

I think it returns the error because it doesn't like spaces.  I tried a few different things and the only way I got the run command to work was when there was no spaces in th files path (in a file or a folder).  The only way I could imagine getting past this is by using the likes of a *.bat file but I'm sure somone else will divise a better method.

EDIT:
   
quote:
Originally posted by -!Felu!-


       
quote:
Originally posted by alexp2_ad
new ActiveXObject('WScript.Shell').run(Messenger.ReceiveFileDir);

   
code:
new ActiveXObject('WScript.Shell').run(Messenger.ReceivedFileDir);
    Should Work :p


alexp2_ad had the correct property, it does not have the extra 'd'
RE: RE: [question] Run commands from script by alexp2_ad on 09-11-2006 at 12:20 PM

quote:
Originally posted by -!Felu!-
quote:
Originally posted by alexp2_ad
new ActiveXObject('WScript.Shell').run(Messenger.ReceiveFileDir);
code:
new ActiveXObject('WScript.Shell').run(Messenger.ReceivedFileDir);
Should Work :p

Nooooooo, I don't like it when people post without checking the scripting docs trying to be a smart arse!

quote:
Objects Reference - Messenger
Messenger::ReceiveFileDir
The Messenger::ReceiveFileDir property returns the path of the directory where files copied by Messenger when a file transfer request is accepted are stored.

Syntax
This is a read-only property.
[string] ReceiveFileDir;


RE: [question] Run commands from script by Spunky on 09-11-2006 at 12:31 PM

quote:
Originally posted by alexp2_ad
you posted a triple backslash first didn't you?

Spelling mistake... I knew what I meant to put :p
RE: [question] Run commands from script by Eljay on 09-11-2006 at 12:48 PM

quote:
Originally posted by markee
I think it returns the error because it doesn't like spaces.  I tried a few different things and the only way I got the run command to work was when there was no spaces in th files path (in a file or a folder).  The only way I could imagine getting past this is by using the likes of a *.bat file but I'm sure somone else will divise a better method.

indeed, it definitely doesnt seem to like spaces.
one way around this is to use the short version of the path which can be retrieved by calling Windows API function GetShortPathName.
Example:
code:
var ShortPath = Interop.Allocate((255+1)*2);
Interop.Call('kernel32', 'GetShortPathNameW', Messenger.ReceiveFileDir, ShortPath, 255);
new ActiveXObject('WScript.Shell').Run(ShortPath.ReadString(0));

Or you could just use ShellExecute, which does accept full paths:
code:
Interop.Call('shell32', 'ShellExecuteW', 0, 'open', Messenger.ReceiveFileDir, 0, 0, 1);

EDIT: zomg 2300 posts!
RE: [question] Run commands from script by markee on 09-11-2006 at 12:58 PM

quote:
Originally posted by Eljay
quote:
Originally posted by markee
I think it returns the error because it doesn't like spaces.  I tried a few different things and the only way I got the run command to work was when there was no spaces in th files path (in a file or a folder).  The only way I could imagine getting past this is by using the likes of a *.bat file but I'm sure somone else will divise a better method.

indeed, it definitely doesnt seem to like spaces.
one way around this is to use the short version of the path which can be retrieved by calling Windows API function GetShortPathName.
Example:
code:
var ShortPath = Interop.Allocate((255+1)*2);
Interop.Call('kernel32', 'GetShortPathNameW', Messenger.ReceiveFileDir, ShortPath, 255);
new ActiveXObject('WScript.Shell').Run(ShortPath.ReadString(0));

Or you could just use ShellExecute, which does accept full paths:
code:
Interop.Call('shell32', 'ShellExecuteW', 0, 'open', Messenger.ReceiveFileDir, 0, 0, 1);

EDIT: zomg 2300 posts!

That works well but you could use this instead if you would prefer to just use ActiveXObjects rather than interop
code:
new ActiveXObject('WScript.Shell').Run(new ActiveXObject("Scripting.FileSystemObject").GetFolder(Messenger.ReceiveFileDir).ShortPath)
Btw, it is only one line long as well which looks nicer :P

EDIT:
I think when you are after a file you will have to change ShortPath to ShortName, though I havent tested this.
RE: RE: RE: [question] Run commands from script by CookieRevised on 09-11-2006 at 04:15 PM

quote:
Originally posted by skorpan
quote:
Originally posted by alexp2_ad
You actually WANT a double \\ for some reason?
...
code:
Messenger.ReceiveFileDir
Returns something like: c:\my documents\my recieved files, right?
This is stored in a string.

Before I can use it with
code:
Shell.Run
I need to change it into: c:\\my documents\\my recieved files.

How do I do that?
You don't!!

The Messenger.ReceiveFileDir (just as other similar functions) returns a proper string already. Do NOT change the slashes to double slashes! This will result in unwanting effects and possible errors.

You need specifiy a double slash ONLY when you type the variable yourself like:

MyString = "here I manually enter some text with some \\ slashes in \\ it and some new lines: \n\n\n hello"

If you print out that variable you'll see:
"here I manually enter some text with some \ slashes in \ it and ...."

As explained before the slash is a special character and means "take the next character literally" (if the next character isn't a control character). So if you enter a string value manually you need to specify a double slash so the programming language knows it must take the second slash literally.

However, when functions return variables, all the charaters inside the variable are already correct; the programming language has already taken the slashes literally:

MyString = Messenger.ReceiveFileDir

If you print out that string you will see again only single slashes as it should be and just the same as with the output of our previous string.

If the returned string wasn't proper formatted you would not see something like "C:\Hello", but you would see "C:Hello".

so... DO NOT CHANGE SLASHES TO DOUBLE SLASHES in strings returned by functions.
RE: [question] Run commands from script by Shondoit on 09-11-2006 at 06:06 PM

It can work with a very simple solution...

I've been working in the registry for a while, changing Shell settings (right-click menu in explorer) and the commands all work when there are spaces....

It's a very simple solution

code:
new ActiveXObject('WScript.Shell').run("\"" + Messenger.ReceiveFileDir + "\"")
Just use quotes (y)
RE: [question] Run commands from script by CookieRevised on 09-12-2006 at 07:46 AM

quote:
Originally posted by Shondoit
It's a very simple solution
code:
new ActiveXObject('WScript.Shell').run("\"" + Messenger.ReceiveFileDir + "\"")
Just use quotes (y)
Which is actually no trick or something, but a basic standard logical thing. Thruout Windows you always must enclose your path in quotes if it contains spaces.;)