What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [question] Run commands from script

Pages: (3): « First « 1 2 [ 3 ] Last »
[question] Run commands from script
Author: Message:
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [question] Run commands from script
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!

This post was edited on 09-11-2006 at 12:53 PM by Eljay.
09-11-2006 12:48 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1621
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: [question] Run commands from script
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.

This post was edited on 09-11-2006 at 02:16 PM by markee.
[Image: markee.png]
09-11-2006 12:58 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: RE: [question] Run commands from script
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.

This post was edited on 09-11-2006 at 04:23 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-11-2006 04:15 PM
Profile PM Find Quote Report
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
35 / Male / Flag
Joined: Jul 2006
RE: [question] Run commands from script
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)
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
09-11-2006 06:06 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [question] Run commands from script
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.;)
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-12-2006 07:46 AM
Profile PM Find Quote Report
Pages: (3): « First « 1 2 [ 3 ] Last »
« 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