Accessing full command line or parameters WITH QUOTES

I'm trying to write a script that manipulates its command line and then runs 
the command line.  E.g.:

myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some file" 
/etc

which would then execute:

"C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file" 
/etc

The problem is that VBScript doesn't allow access to the full command line 
like most other languages.  Furthermore, the individual parameters get the 
quotes stripped, so WScript.Arguments returns:

C:\Full Path\Program.exe
/optionSome other option
C:\Some file
/etc

which is completely assinine because there is no way for me to know how 
rebuild the parameters with the quotes inserted properly.  What idiot thought 
it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A 
PARAMETER??!?  Sorry...I'll stop ranting.  I'm just flabbergasted that 
someone thought it was good idea to manipulate parameters before passing them 
to our scripts.

When I was writing the script on XP, I managed to cheat and grab the CmdLine 
environment variable.  However, I need the script to run on Win2008, and it 
doesn't have the CmdLine variable, so I'm out of luck there.

So how do I get around this?  How can I either (1) get access to the full 
command line similar to the CmdLine environment variable, or (2) get access 
to the full, properly quoted parameters?
0
Utf
11/28/2009 12:03:01 AM
scripting.vbscript 564 articles. 0 followers. Follow

8 Replies
1422 Views

Similar Articles

[PageSpeed] 12

On Nov 27, 7:03=A0pm, Bennett <Benn...@discussions.microsoft.com> wrote:
> I'm trying to write a script that manipulates its command line and then r=
uns
> the command line. =A0E.g.:
>
> myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some fil=
e"
> /etc
>
> which would then execute:
>
> "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file=
"
> /etc
>
> The problem is that VBScript doesn't allow access to the full command lin=
e
> like most other languages. =A0Furthermore, the individual parameters get =
the
> quotes stripped, so WScript.Arguments returns:
>
> C:\Full Path\Program.exe
> /optionSome other option
> C:\Some file
> /etc
>
> which is completely assinine because there is no way for me to know how
> rebuild the parameters with the quotes inserted properly. =A0What idiot t=
hought
> it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> PARAMETER??!? =A0Sorry...I'll stop ranting. =A0I'm just flabbergasted tha=
t
> someone thought it was good idea to manipulate parameters before passing =
them
> to our scripts.
>
> When I was writing the script on XP, I managed to cheat and grab the CmdL=
ine
> environment variable. =A0However, I need the script to run on Win2008, an=
d it
> doesn't have the CmdLine variable, so I'm out of luck there.
>
> So how do I get around this? =A0How can I either (1) get access to the fu=
ll
> command line similar to the CmdLine environment variable, or (2) get acce=
ss
> to the full, properly quoted parameters?

That's a tough one.  However, the WMI Win34_Processes class can return
that information ...

Set oWMISrvc =3D GetObject("winmgmts:" _
    & "{impersonationLevel=3Dimpersonate}!\\.\root\cimv2")

sProcName =3D Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)

Set cProcesses =3D oWMISrvc.ExecQuery( _
    "select * from win32_process where Name =3D '" & sProcName & "'")

For Each oProcess in cProcesses
  If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0
Then
    wsh.echo oProcess.Commandline
  End If
Next

This presumes there is only one instance of that particular script
running.  Otherwise, it finds the LAST one started, which should suit
your purposes, anyway.  I have no idea how to do it in 64 bit mode.  I
only have access to 32 bit OS equipped machines.
____________________
Tom Lavedas
0
Tom
11/28/2009 1:12:24 AM
"Bennett" <Bennett@discussions.microsoft.com> wrote in message 
news:0AF8A657-356A-4F70-B779-901DF2B58ECA@microsoft.com...
> I'm trying to write a script that manipulates its command line and then 
> runs
> the command line.  E.g.:
>
> myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some 
> file"
> /etc
>
> which would then execute:
>
> "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file"
> /etc
>
> The problem is that VBScript doesn't allow access to the full command line
> like most other languages.  Furthermore, the individual parameters get the
> quotes stripped, so WScript.Arguments returns:
>
> C:\Full Path\Program.exe
> /optionSome other option
> C:\Some file
> /etc
>
> which is completely assinine because there is no way for me to know how
> rebuild the parameters with the quotes inserted properly.  What idiot 
> thought
> it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> PARAMETER??!?  Sorry...I'll stop ranting.  I'm just flabbergasted that
> someone thought it was good idea to manipulate parameters before passing 
> them
> to our scripts.
>
> When I was writing the script on XP, I managed to cheat and grab the 
> CmdLine
> environment variable.  However, I need the script to run on Win2008, and 
> it
> doesn't have the CmdLine variable, so I'm out of luck there.
>
> So how do I get around this?  How can I either (1) get access to the full
> command line similar to the CmdLine environment variable, or (2) get 
> access
> to the full, properly quoted parameters?

I think your script must handle the situations. Any parameter with embedded 
spaces must be enclosed in quotes. The script must recognize that any 
parameter that might have embedded spaces should always be enclosed in 
quotes by the script. In all cases I can think of it will not hurt. In your 
example I would say the second parameter is invalid. There should be a space 
between /option and "Some other option", so the script can parse it as two 
parameters and make sense of it. In other words, there should never be 
embedded quotes, only quotes that completely enclose the string.

The only insurmountable problem I've encountered is the inability to include 
any quote characters in a parameter. For example I cannot pass the string:

GetObject("LDAP:")

to a script. However, the only time I have had the need to do this is a 
script that searches for files that contain specified text strings.

Finally, another solution might be to place the parameters in a text file 
and have the VBScript program read the file using the FileSystemObject. No 
quotes are stripped off.

-- 
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
-- 


0
Richard
11/28/2009 1:19:04 AM
On Nov 28, 1:03=A0am, Bennett <Benn...@discussions.microsoft.com> wrote:
> I'm trying to write a script that manipulates its command line and then r=
uns
> the command line. =A0E.g.:
>
> myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some fil=
e"
> /etc
>
> which would then execute:
>
> "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file=
"
> /etc
>
> The problem is that VBScript doesn't allow access to the full command lin=
e
> like most other languages. =A0Furthermore, the individual parameters get =
the
> quotes stripped, so WScript.Arguments returns:
>
> C:\Full Path\Program.exe
> /optionSome other option
> C:\Some file
> /etc
>
> which is completely assinine because there is no way for me to know how
> rebuild the parameters with the quotes inserted properly. =A0What idiot t=
hought
> it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> PARAMETER??!? =A0Sorry...I'll stop ranting. =A0I'm just flabbergasted tha=
t
> someone thought it was good idea to manipulate parameters before passing =
them
> to our scripts.

Um, I hate to get in the way of a perfectly good rant,
but that idiot, as you say, is DOS or the Cmd Window
parser, whose function, in this case, is to parse
command line arguments.  Since command line
arguments might have spaces in them, or even quotes
for that matter, there must be a mechanism for
escaping them, wouldn't you say?

So the question is really, what is that escape?  And the
answer is that the primary escape mechanism is double
quotes.  If we take your example, that you want to pass
/option"Three little words"
as one argument to your script, where does that leave
the guy who want to pass
/option"Thee little words" and three more
as a single argument to their script?

You can get double quotes into your argument, but you
should escape them with a backslash.  For example, the
following will run the php script (assuming php is
installed) that is the 2nd (and last) argument to php:
php -r "print \"Hi mom\";"

So in your example, since you need to quote the spaces,
you might do:
/option"\"Three little words\""

But wouldn't it be better to allow/require either
/option: "Three little words"
or
/option:"Three little words"

> When I was writing the script on XP, I managed to cheat and grab the CmdL=
ine
> environment variable. =A0However, I need the script to run on Win2008, an=
d it
> doesn't have the CmdLine variable, so I'm out of luck there.

I have Win XP Pro, but I've never seen this
CmdLine environment variable.  Perhaps you could
elaborate, pleas.  I just checked with the following
one line script and no CmdLine shows for me:
php -r "foreach ($_ENV as $key =3D> $env) print \"$key =3D^> $env\n\";"
By the way, notice the ^ escaping the > within the string.

Csaba Gabor from Vienna

> So how do I get around this? =A0How can I either (1) get access to the fu=
ll
> command line similar to the CmdLine environment variable, or (2) get acce=
ss
> to the full, properly quoted parameters?
0
Csaba
11/28/2009 1:26:13 AM
On Nov 27, 8:12=A0pm, Tom Lavedas <tlave...@gmail.com> wrote:
> On Nov 27, 7:03=A0pm, Bennett <Benn...@discussions.microsoft.com> wrote:
>
>
>
> > I'm trying to write a script that manipulates its command line and then=
 runs
> > the command line. =A0E.g.:
>
> > myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some f=
ile"
> > /etc
>
> > which would then execute:
>
> > "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other fi=
le"
> > /etc
>
> > The problem is that VBScript doesn't allow access to the full command l=
ine
> > like most other languages. =A0Furthermore, the individual parameters ge=
t the
> > quotes stripped, so WScript.Arguments returns:
>
> > C:\Full Path\Program.exe
> > /optionSome other option
> > C:\Some file
> > /etc
>
> > which is completely assinine because there is no way for me to know how
> > rebuild the parameters with the quotes inserted properly. =A0What idiot=
 thought
> > it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> > PARAMETER??!? =A0Sorry...I'll stop ranting. =A0I'm just flabbergasted t=
hat
> > someone thought it was good idea to manipulate parameters before passin=
g them
> > to our scripts.
>
> > When I was writing the script on XP, I managed to cheat and grab the Cm=
dLine
> > environment variable. =A0However, I need the script to run on Win2008, =
and it
> > doesn't have the CmdLine variable, so I'm out of luck there.
>
> > So how do I get around this? =A0How can I either (1) get access to the =
full
> > command line similar to the CmdLine environment variable, or (2) get ac=
cess
> > to the full, properly quoted parameters?
>
> That's a tough one. =A0However, the WMI Win34_Processes class can return
> that information ...
>
> Set oWMISrvc =3D GetObject("winmgmts:" _
> =A0 =A0 & "{impersonationLevel=3Dimpersonate}!\\.\root\cimv2")
>
> sProcName =3D Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
>
> Set cProcesses =3D oWMISrvc.ExecQuery( _
> =A0 =A0 "select * from win32_process where Name =3D '" & sProcName & "'")
>
> For Each oProcess in cProcesses
> =A0 If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0
> Then
> =A0 =A0 wsh.echo oProcess.Commandline
> =A0 End If
> Next
>
> This presumes there is only one instance of that particular script
> running. =A0Otherwise, it finds the LAST one started, which should suit
> your purposes, anyway. =A0I have no idea how to do it in 64 bit mode. =A0=
I
> only have access to 32 bit OS equipped machines.
> ____________________
> Tom Lavedas

Wait, it finds them all.  This finds the last one ...

Set oWMISrvc =3D GetObject("winmgmts:" _
    & "{impersonationLevel=3Dimpersonate}!\\.\root\cimv2")

sProcName =3D Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)

Set cProcesses =3D oWMISrvc.ExecQuery( _
    "select * from win32_process where Name =3D '" & sProcName & "'")

For Each oProcess in cProcesses
  If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0
Then
    sCmdLine =3D oProcess.Commandline
  End If
Next
wsh.echo sCmdLine
0
Tom
11/28/2009 1:43:31 AM
"Csaba Gabor" <danswer@gmail.com> wrote in message 
news:86a52646-f78e-4559-bbf7-09c865876781@e27g2000yqd.googlegroups.com...
On Nov 28, 1:03 am, Bennett <Benn...@discussions.microsoft.com> wrote:
> I'm trying to write a script that manipulates its command line and then 
> runs
> the command line. E.g.:
>
> myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some 
> file"
> /etc
>
> which would then execute:
>
> "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file"
> /etc
>
> The problem is that VBScript doesn't allow access to the full command line
> like most other languages. Furthermore, the individual parameters get the
> quotes stripped, so WScript.Arguments returns:
>
> C:\Full Path\Program.exe
> /optionSome other option
> C:\Some file
> /etc
>
> which is completely assinine because there is no way for me to know how
> rebuild the parameters with the quotes inserted properly. What idiot 
> thought
> it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> PARAMETER??!? Sorry...I'll stop ranting. I'm just flabbergasted that
> someone thought it was good idea to manipulate parameters before passing 
> them
> to our scripts.

Um, I hate to get in the way of a perfectly good rant,
but that idiot, as you say, is DOS or the Cmd Window
parser, whose function, in this case, is to parse
command line arguments.  Since command line
arguments might have spaces in them, or even quotes
for that matter, there must be a mechanism for
escaping them, wouldn't you say?

So the question is really, what is that escape?  And the
answer is that the primary escape mechanism is double
quotes.  If we take your example, that you want to pass
/option"Three little words"
as one argument to your script, where does that leave
the guy who want to pass
/option"Thee little words" and three more
as a single argument to their script?

You can get double quotes into your argument, but you
should escape them with a backslash.  For example, the
following will run the php script (assuming php is
installed) that is the 2nd (and last) argument to php:
php -r "print \"Hi mom\";"

So in your example, since you need to quote the spaces,
you might do:
/option"\"Three little words\""

But wouldn't it be better to allow/require either
/option: "Three little words"
or
/option:"Three little words"

> When I was writing the script on XP, I managed to cheat and grab the 
> CmdLine
> environment variable. However, I need the script to run on Win2008, and it
> doesn't have the CmdLine variable, so I'm out of luck there.

I have Win XP Pro, but I've never seen this
CmdLine environment variable.  Perhaps you could
elaborate, pleas.  I just checked with the following
one line script and no CmdLine shows for me:
php -r "foreach ($_ENV as $key => $env) print \"$key =^> $env\n\";"
By the way, notice the ^ escaping the > within the string.

Csaba Gabor from Vienna

> So how do I get around this? How can I either (1) get access to the full
> command line similar to the CmdLine environment variable, or (2) get 
> access
> to the full, properly quoted parameters?

==========

Since WMI will report the exact command line, with double quotes, it must be 
the parameter processing routine of cscript/wscript that strips the double 
quotes. And attempting to escape double quotes by using strings such as 
/option"\"Three little words\""  will  not prevent cscript/vbscript from 
showing the parameters minus the double quotes. On the other hand some 
executables will display the double quotes. Try this one for fun:

mem "abc 


0
Pegasus
11/28/2009 11:22:44 AM
On Nov 28, 12:22=A0pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Csaba Gabor" <dans...@gmail.com> wrote in message
>
> news:86a52646-f78e-4559-bbf7-09c865876781@e27g2000yqd.googlegroups.com...
> On Nov 28, 1:03 am, Bennett <Benn...@discussions.microsoft.com> wrote:
>
> > I'm trying to write a script that manipulates its command line and then
> > runs
> > the command line. E.g.:
>
> > myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some
> > file"
> > /etc
>
> > which would then execute:
>
> > "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other fi=
le"
> > /etc
>
> > The problem is that VBScript doesn't allow access to the full command l=
ine
> > like most other languages. Furthermore, the individual parameters get t=
he
> > quotes stripped, so WScript.Arguments returns:
>
> > C:\Full Path\Program.exe
> > /optionSome other option
> > C:\Some file
> > /etc
>
> > which is completely assinine because there is no way for me to know how
> > rebuild the parameters with the quotes inserted properly. What idiot
> > thought
> > it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> > PARAMETER??!? Sorry...I'll stop ranting. I'm just flabbergasted that
> > someone thought it was good idea to manipulate parameters before passin=
g
> > them
> > to our scripts.
>
> Um, I hate to get in the way of a perfectly good rant,
> but that idiot, as you say, is DOS or the Cmd Window
> parser, whose function, in this case, is to parse
> command line arguments. =A0Since command line
> arguments might have spaces in them, or even quotes
> for that matter, there must be a mechanism for
> escaping them, wouldn't you say?
>
> So the question is really, what is that escape? =A0And the
> answer is that the primary escape mechanism is double
> quotes. =A0If we take your example, that you want to pass
> /option"Three little words"
> as one argument to your script, where does that leave
> the guy who want to pass
> /option"Thee little words" and three more
> as a single argument to their script?
>
> You can get double quotes into your argument, but you
> should escape them with a backslash. =A0For example, the
> following will run the php script (assuming php is
> installed) that is the 2nd (and last) argument to php:
> php -r "print \"Hi mom\";"
>
> So in your example, since you need to quote the spaces,
> you might do:
> /option"\"Three little words\""
>
> But wouldn't it be better to allow/require either
> /option: "Three little words"
> or
> /option:"Three little words"
>
> > When I was writing the script on XP, I managed to cheat and grab the
> > CmdLine
> > environment variable. However, I need the script to run on Win2008, and=
 it
> > doesn't have the CmdLine variable, so I'm out of luck there.
>
> I have Win XP Pro, but I've never seen this
> CmdLine environment variable. =A0Perhaps you could
> elaborate, pleas. =A0I just checked with the following
> one line script and no CmdLine shows for me:
> php -r "foreach ($_ENV as $key =3D> $env) print \"$key =3D^> $env\n\";"
> By the way, notice the ^ escaping the > within the string.
>
> Csaba Gabor from Vienna
>
> > So how do I get around this? How can I either (1) get access to the ful=
l
> > command line similar to the CmdLine environment variable, or (2) get
> > access
> > to the full, properly quoted parameters?
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> Since WMI will report the exact command line,
> with double quotes,

Um, that's not quite true, is it?  Let me give some
examples:

If my .vbs file has the code that Tom Lavedas
suggested in his second post:
> Set oWMISrvc =3D GetObject("winmgmts:" _
>     & "{impersonationLevel=3Dimpersonate}!\\.\root\cimv2")
>
> sProcName =3D _
>   Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
>
> Set cProcesses =3D oWMISrvc.ExecQuery( _
>     "select * from win32_process where Name =3D '" & _
>     sProcName & "'")
>
> For Each oProcess in cProcesses
>   If Instr(lcase(oProcess.Commandline), _
               lcase(wsh.scriptname)) > 0 Then
>     sCmdLine =3D oProcess.Commandline
>   End If
> Next
> wsh.echo sCmdLine

then when I attempt to run it by:
myfile.vbs
the returned command line is actually:
"C:\WINDOWS\System32\WScript.exe" "C:\delme\myfile.vbs"

This is a 'reprocessed' command line, no?  But still,
our real issue is the arguments.  So if I try to invoke:
myfile.vbs "\"one =3D^> two\""
Then for that argument, I'll actually be shown:
myfile.vbs "\"one =3D> two\""

> it must be the parameter processing routine of
> cscript/wscript that strips the double quotes.

I find your argument interesting, but not convincing.
There could be other avenues.  But I do agree that
WScript is removing at least one pair of quotes

> And attempting to escape double quotes by using
> strings such as /option"\"Three little words\"" =A0will
> not prevent cscript/vbscript from showing the
> parameters minus the double quotes.

This is a very interesting point.  I fed VBScript the
following argument:
"\"one =3D two\""
and VBScript turned it into 3: one, =3D, two
and there were no more double quotes.  If I removed
the spaces on either side of the double quotes then
VBScript reported only one argument (also without
double quotes).  PHP, on the other hand, preserved
one pair of double quotes and treated it only as a
single argument (regardless of spaces).  I think  that
strongly implies VBScript is doing some post
processing on the command line argument.

In any case, my earlier recommendation of escaping the
double quotes by prefixing them with a backslash does
not work with VBScript, but it does work with PHP (as
shown with the following one line script).

php -r "$w=3Dnew COM('winmgmts:{impersonationLevel=3Dimpersonate}!\\\\.\
\root\\cimv2');$cProc=3D$w->ExecQuery('select * from
win32_process');foreach ($cProc as $i=3D>$proc) print \"$i=3D^>\".$proc-
>CommandLine.\"\n\";"

> On the other hand some
> executables will display the double quotes. Try this one for fun:
>
> mem "abc
0
Csaba
11/28/2009 1:24:59 PM
"Csaba Gabor" <danswer@gmail.com> wrote in message
news:869831bb-3bf1-4404-8454-13875a4f9d0a@r5g2000yqb.googlegroups.com...
On Nov 28, 12:22 pm, "Pegasus [MVP]" <n...@microsoft.com> wrote:
> "Csaba Gabor" <dans...@gmail.com> wrote in message
>
> news:86a52646-f78e-4559-bbf7-09c865876781@e27g2000yqd.googlegroups.com...
> On Nov 28, 1:03 am, Bennett <Benn...@discussions.microsoft.com> wrote:
>
> > I'm trying to write a script that manipulates its command line and then
> > runs
> > the command line. E.g.:
>
> > myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some
> > file"
> > /etc
>
> > which would then execute:
>
> > "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other
> > file"
> > /etc
>
> > The problem is that VBScript doesn't allow access to the full command
> > line
> > like most other languages. Furthermore, the individual parameters get
> > the
> > quotes stripped, so WScript.Arguments returns:
>
> > C:\Full Path\Program.exe
> > /optionSome other option
> > C:\Some file
> > /etc
>
> > which is completely assinine because there is no way for me to know how
> > rebuild the parameters with the quotes inserted properly. What idiot
> > thought
> > it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> > PARAMETER??!? Sorry...I'll stop ranting. I'm just flabbergasted that
> > someone thought it was good idea to manipulate parameters before passing
> > them
> > to our scripts.
>
> Um, I hate to get in the way of a perfectly good rant,
> but that idiot, as you say, is DOS or the Cmd Window
> parser, whose function, in this case, is to parse
> command line arguments. Since command line
> arguments might have spaces in them, or even quotes
> for that matter, there must be a mechanism for
> escaping them, wouldn't you say?
>
> So the question is really, what is that escape? And the
> answer is that the primary escape mechanism is double
> quotes. If we take your example, that you want to pass
> /option"Three little words"
> as one argument to your script, where does that leave
> the guy who want to pass
> /option"Thee little words" and three more
> as a single argument to their script?
>
> You can get double quotes into your argument, but you
> should escape them with a backslash. For example, the
> following will run the php script (assuming php is
> installed) that is the 2nd (and last) argument to php:
> php -r "print \"Hi mom\";"
>
> So in your example, since you need to quote the spaces,
> you might do:
> /option"\"Three little words\""
>
> But wouldn't it be better to allow/require either
> /option: "Three little words"
> or
> /option:"Three little words"
>
> > When I was writing the script on XP, I managed to cheat and grab the
> > CmdLine
> > environment variable. However, I need the script to run on Win2008, and
> > it
> > doesn't have the CmdLine variable, so I'm out of luck there.
>
> I have Win XP Pro, but I've never seen this
> CmdLine environment variable. Perhaps you could
> elaborate, pleas. I just checked with the following
> one line script and no CmdLine shows for me:
> php -r "foreach ($_ENV as $key => $env) print \"$key =^> $env\n\";"
> By the way, notice the ^ escaping the > within the string.
>
> Csaba Gabor from Vienna
>
> > So how do I get around this? How can I either (1) get access to the full
> > command line similar to the CmdLine environment variable, or (2) get
> > access
> > to the full, properly quoted parameters?
>
> ==========
>
> Since WMI will report the exact command line,
> with double quotes,

Um, that's not quite true, is it?  Let me give some
examples:

If my .vbs file has the code that Tom Lavedas
suggested in his second post:
> Set oWMISrvc = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\.\root\cimv2")
>
> sProcName = _
>   Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
>
> Set cProcesses = oWMISrvc.ExecQuery( _
>     "select * from win32_process where Name = '" & _
>     sProcName & "'")
>
> For Each oProcess in cProcesses
>   If Instr(lcase(oProcess.Commandline), _
               lcase(wsh.scriptname)) > 0 Then
>     sCmdLine = oProcess.Commandline
>   End If
> Next
> wsh.echo sCmdLine

then when I attempt to run it by:
myfile.vbs
the returned command line is actually:
"C:\WINDOWS\System32\WScript.exe" "C:\delme\myfile.vbs"

This is a 'reprocessed' command line, no?  But still,
our real issue is the arguments.  So if I try to invoke:
myfile.vbs "\"one =^> two\""
Then for that argument, I'll actually be shown:
myfile.vbs "\"one => two\""

> it must be the parameter processing routine of
> cscript/wscript that strips the double quotes.

I find your argument interesting, but not convincing.
There could be other avenues.  But I do agree that
WScript is removing at least one pair of quotes

You initially wrote "that idiot, as you say, is DOS or the Cmd Window
parser, whose function, in this case, is to parse command line arguments."
If I can find just one command that gets processed by the command parser and
that preserves at least some double quotes then your claim cannot be
correct. The command below is such an example:

mem "abc

Since mem.exe is an external command it does get processed and parsed by the
command processor. It follows that the command processor preserves at least
some double quotes. There must be another agent that strips the lot and the
finger points to cscript.exe.



0
Pegasus
11/28/2009 4:00:57 PM

"Tom Lavedas" wrote:

> On Nov 27, 8:12 pm, Tom Lavedas <tlave...@gmail.com> wrote:
> > On Nov 27, 7:03 pm, Bennett <Benn...@discussions.microsoft.com> wrote:
> >
> >
> >
> > > I'm trying to write a script that manipulates its command line and then runs
> > > the command line.  E.g.:
> >
> > > myscript.vbs "C:\Full Path\Program.exe" /option"Some option" "C:\Some file"
> > > /etc
> >
> > > which would then execute:
> >
> > > "C:\Full Path\Program.exe" /option"Some other option" "C:\Some other file"
> > > /etc
> >
> > > The problem is that VBScript doesn't allow access to the full command line
> > > like most other languages.  Furthermore, the individual parameters get the
> > > quotes stripped, so WScript.Arguments returns:
> >
> > > C:\Full Path\Program.exe
> > > /optionSome other option
> > > C:\Some file
> > > /etc
> >
> > > which is completely assinine because there is no way for me to know how
> > > rebuild the parameters with the quotes inserted properly.  What idiot thought
> > > it would be a good idea to strip all quotes INCLUDING THOSE INSIDE A
> > > PARAMETER??!?  Sorry...I'll stop ranting.  I'm just flabbergasted that
> > > someone thought it was good idea to manipulate parameters before passing them
> > > to our scripts.
> >
> > > When I was writing the script on XP, I managed to cheat and grab the CmdLine
> > > environment variable.  However, I need the script to run on Win2008, and it
> > > doesn't have the CmdLine variable, so I'm out of luck there.
> >
> > > So how do I get around this?  How can I either (1) get access to the full
> > > command line similar to the CmdLine environment variable, or (2) get access
> > > to the full, properly quoted parameters?
> >
> > That's a tough one.  However, the WMI Win34_Processes class can return
> > that information ...
> >
> > Set oWMISrvc = GetObject("winmgmts:" _
> >     & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> >
> > sProcName = Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
> >
> > Set cProcesses = oWMISrvc.ExecQuery( _
> >     "select * from win32_process where Name = '" & sProcName & "'")
> >
> > For Each oProcess in cProcesses
> >   If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0
> > Then
> >     wsh.echo oProcess.Commandline
> >   End If
> > Next
> >
> > This presumes there is only one instance of that particular script
> > running.  Otherwise, it finds the LAST one started, which should suit
> > your purposes, anyway.  I have no idea how to do it in 64 bit mode.  I
> > only have access to 32 bit OS equipped machines.
> > ____________________
> > Tom Lavedas
> 
> Wait, it finds them all.  This finds the last one ...
> 
> Set oWMISrvc = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> 
> sProcName = Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
> 
> Set cProcesses = oWMISrvc.ExecQuery( _
>     "select * from win32_process where Name = '" & sProcName & "'")
> 
> For Each oProcess in cProcesses
>   If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0
> Then
>     sCmdLine = oProcess.Commandline
>   End If
> Next
> wsh.echo sCmdLine
> .
> 

Thanks, Tom.  You rock.  BTW, works on Win2008 64-bit, too.  Wish there was 
a way to just get the script's process directly instead of hoping the last is 
the correct one, but for my (current) purposes I'll only be running this 
script one at a time.
0
Utf
11/29/2009 3:54:01 AM
Reply:

Similar Artilces:

Need Help Adding Line to Bar Graph
Hi, I�m working on a bar graph with 2 series of comparable data � firs series is YTD @ Current Month, second series is Current Month. I woul like to add 2 lines to show the system (or overall) average of bot series. (x-axis=co region; y-axis= score) How do I do this? I do not want a trending line. I just want straight line to show overall average. Right now, I�m just drawing line on the chart but I would like something that will adjust t updated data. Any help is greatly appreciated -- jcstoddar ----------------------------------------------------------------------- jcstoddard'...

Border lines on the side of the date cell partially missing
Outlook 2003 (version 11.8118.8107) on XP SP2 Pro. As of few days ago my Calendar appears with the border lines on the side of the date cell partially missing. They are white or gray roughly the height of the adjacent date number, while the rest of the line is OK (black). Any ideas? I'm trying to picture this...can you give me a little more detail? What view are you using? (monthly, daily, etc) Which side? (right, left) Could it be that you have an appointment booked during that time? Nikki Peterson "Jerry" <duncan_jeremy@hotmail.com> wrote in message news:...

Send from "role" email
So, we just transitioned from an ISP hosted email to Exchange 2003 SP2. The office manager always used "info@company.com" for sending and receiving emails. Now we have her set up with her own name for login and emails/Mailbox... and also have her receiving the inbound emails that are addressed to "info@company.com". Seems to be working inbound just fine... except if we try to send emails changing the "From" herID to "info@company.com" -- it will not send emails. I think she'll want to continue using this "role" email for most corresp...

"FileDialogOpen"
xl03 I'm using "Application.FileDialog(msoFileDialogOpen)" to present a list of files to the user so he/she can select a wb to load. My question is, can I somehow force the dialog to open with a specific directory? -- Regards Rob (Most of this was stolen from the help for .filedialog) Option Explicit Sub testme() Dim lngCount As Long Dim curFolder As String Dim newFolder As String curFolder = CurDir newFolder = "C:\test" ChDrive newFolder ChDir newFolder ' Open the file dialog With Application.FileDialog(msoFileD...

Custom Line Width in Line or Scatter Chart
Is there any way to create lines of a custom width in a line or scatter chart? I occasionally have a need for a very thick line, thicher than the maximum that the dialog allows? Thanks. Marvin - You can fake it. I have published a few macros that draw lines and other shapes which trace lines on a chart: http://peltiertech.com/Excel/Charts/VBAdraw.html - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions http://PeltierTech.com _______ "Marvin" <Marvin@discussions.microsoft.com> wrote in message news:9EEBCF8D-2F37-4F6A-9FA3-2D82D845F1BE@mic...

How do I populate the "Find" dialogue in Word with the contents of the clipboard?
Hi I tried, and failed to create a macro. (I do a procedure hundreds of times every day so wanted to automate it) I press Control-F (to open the 'find' dialogue) and then press Control- V (to paste the contents) into the dialogue. As you can see from the code below, when I recorded the macro, it used '2022' (which is what happens to be in my clipboard right now) but I want it to use the clipboard. Is this possible? I hope I've explained the problem properly. ==================================================== Sub FindWhatsinClipboar...

unable to download stock quotes
I'm trying to update stock quotes (less than 50 quotes), it doesn't appear to be working. In the call summary I get a message unable to connect to the online quote server, check your internet connection. It appears to have checked for Money update and the call was suscessful. I'm connecting over a cable modem. I have a connection to the internet, I can get email, view web pages, connect to MSN and get current stock quotes. I'm running XP and Money 2004 Warren In microsoft.public.money, Warren wrote: >I'm trying to update stock quotes (less than 50 quotes), it &...

Editing the Subject Line of Incoming Mail
How do you edit the subject line of mail you have received in Microsoft Outlook Express? I'm using Windows 98 and Outlook Express 5. I often keep my e-mail -- to respond later -- but would like to remember what the subject was of certain e-mails. If the sender did not put a subject, or if the subject doesn't reflect how I would like to remember that e-mail, how do I change the subject and keep it in my inbox? ...

Creating more than 1 line in a cell
Is there any way to create more than one line in a cell? You cannot use the RETURN or TAB keys since they take you to another cell. I tried using three cells and then merging into one, but then it only keeps the information form the uppermost cell and then deletes the data in the other two cells. Text-wrapping doesn't work because if the word(s) on the top line is long enough, then I have to add several spaces before it will be forced to go down to a second line. I've tried Excel Help, but it goes to autoformat and none of the formats are the ones that I want. Thank...

return a "0" instead of a blank field
When I run my query I have some blank feils. I would like to have those fields to contain a zeor instead of being null. I've tried writting an IIF statement but programming eludes me. Please help. Thank you If you are using design view, try the following as a calculated field. Field: SomeFieldZero: IIF([SomeField] is Null,0,[SomeField] '==================================================== John Spencer Access MVP 2002-2005, 2007 Center for Health Program Development and Management University of Maryland Baltimore County '============================================...

message: can't access outlook.pst
hi when i try to sendqreceive i get a message the file C:\WINDOWS\outlook.pst could not be accessed is it a virus? what do i do? thanks ari >-----Original Message----- >hi >when i try to sendqreceive i get a message the file >C:\WINDOWS\outlook.pst could not be accessed >is it a virus? >what do i do? >thanks >ari >. Find the backup by finding file c:\win\localsettings\applicationdata\Microsoft\outlook*.pst and it should come up, rename and swap over the current and backup (you will need to close Outlook). To retrieve your data, you need to archive all yo...

Followup:Add vertical line at intersection of 2 curves (Ping Andy Pope)
Okay, I've been hammering away at this for days now, and I *still* just do not get it. I've been _trying_ to use the user-defined function created by Andy Pope (http://www.andypope.info/charts/intersection.htm) to find all the intersecting points of 2 "lines" (actually xy scatter plots with visible markers) on a chart, and then create a vertical line (or multiple lines) on the chart at the intersection point (or points). I downloaded the intersection demo .zip file. I copied both procedures from the demo into my workbook. I changed all my column/field names to ma...

Field criteria happens to be a wildcard
Hi, The table has a field that contains a star (*), which probably also is a wildcard in Access language. Anyhow, I want to use the star as a field critera, but not very surprising it doesn't work as intended... instead of ONLY showing records with a stat (*) it shows ALL RECORDS. Is there a way to tell Access that "*" really means that, and not a wildcard? Kindly, Mikael L Sweden Try putting square brackets around the asterisk: WHERE MyField = "[*]" -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Mikael Lindqv...

Subject line changes when forwarding meeting requests
I have setup some conference rooms in outlook. These work fine for scheduling but our group admin likes to forward these to her helper. In the subject line she likes to put who requested the meeting. Problem is when she forwards the meeting request it always overwrites the information in the subject line with the person's name who forwared the Email. Any way to make it not do that? Why does it do that? That sounds like a setting on Exchange server. You'll need to speak to the admin and ask them to change it - I think this has the right comdlet to use: http://technet....

convert "less than" value from ppb to ppm
Need a formula to change values from parts per billion to parts per million, but need to have formula to check for "less than" and complete conversion. 51 would be 0.051 <5 would be <0.005 THANKS =if(left(a1,1)="<","<"&right(a1,len(a1)-1)/1000,a1/1000) Regards, Fred "rlihle1" <rlihle1@discussions.microsoft.com> wrote in message news:57F24270-A4E3-4F9C-BBFC-58992E9B5E2A@microsoft.com... > Need a formula to change values from parts per billion to parts per > million, > but need to have formula to ...

ANN: nxslt (.NET XSLT Command Line Utility) version 1.4
Hello! I'm glad to announce version 1.4 of nxslt - .NET XSLT command line utility. It's maintenance release. What is nxslt ------------- nxslt is a feature-rich command line utility that allows to perform XSL Transformations (XSLT) using .NET Framework's XSLT implementation - System.Xml.Xsl.XslTransform class. nxslt basically dublicates functionality and command line options, provided by Microsoft's MSXSL.EXE Command Line Transformation Utility. In addition, nxslt has some distinct advanced features, like support for XInclude, embedded stylesheets, custom URI resolving, mult...

Tracking "Outbound messages awaiting delivery"
Currently running Exchange 5.5 (in an NT 4.0 domain). In Exchange Admin, under Internet Mail Service, Queues: Under the Outbound messages awaiting delivery -- this queue is constantly being populated by what I would consider junk mail. The destination addresses seem to be very bogus. The orginator is almost always <> (it looks like the origin is unknown). How can I track these messages down and make sure that they do not appear in my outbound queue?? Thank you in advance, TR "Timothy Ross" <ross_timothy@hotmail.com> wrote in news:e7iousL8DHA.2316@TK2MSFTNGP09.ph...

How to access a static member variable within __asm { }
Hello everybody, I am trying to access a static member variable within an __asm { } code but the compiler always tells me that its not know. If you access the variable outside the __asm { } code its working. When I try to access inside, I can only access variables that are declared/defined within the same function. I tryed "Class::variable" and "variable" but nothing is recognized from the compiler. Do you have any hint to access the static variables, without defining pointer-variables in the function? Best Regards Maybe you may transfer the address of the stati...

typing text onto two lines (one above the other) in one cell
What is the command and syntax to do the above? Thank you. Will, Press the Alt-Enter keys at the same time in a sentence to go to a different line within the same cell. ---- Regards, John Mansfield http://www.pdbook.com "Will Naylor" wrote: > What is the command and syntax to do the above? > > Thank you. > ...

outlook works a while then goes into "not responding"
. Reply (E-mail) Forward (E-mail) Subject: oUTLOOK 2002 From: "vingman" <anonymous@discussions.microsoft.com> Sent: 1/6/2004 1:24:20 AM this is a repost from my earlier message which had a uselessly broad subject I recently added Norton Internet Security and now my outlook freezes after a few actions, i can open a few emails or send some but after a short while i get the dreaded "not responding". i tried uninstalling internet security but outlook still didn't work. i also fixed the pst file with the microsoft utility (it found errors, th...

Visual Foxpro conversion for Access 2003
In Access 2000 I was able to import from Foxpro, under the option of File Type being ODBC and then the tab for Machine Data sources. This option set is not present in Access 2003, and I cannot load Access 2000 on my new XP- based machines as my upgrade path on the old machine was going back to upgrades which my new machine won't allow me to install the old CDs on. Thanks in advance. Hi Pete, I'm not an Access guru but here's what worked - If you Ctrl+F1 to bring up the task pane and choose Blank database (top of the list) you get an MDB instead of an ADP. With the MDB yo...

Default Word 2007 to "No Spacing"?
Is there a setting to make Word 2007 default to use "No Spacing" under the Styles of the Home Tab? It's very annoying that it defaults to normal. I never use it!!! It's especially when doing a Mail Merge and I have to put Name, Name2, Contact, Address, Address2, etc.. all on one tiny label. Can't do that with the spacing it does by normal. Each time I have to change it to no spacing. Apply the Word 2003 style set. (Change Styles on the Home Tab) -- <>>< ><<> ><<> <>>< ><<> <>>< ...

Auto Stock Quote Updates
Does anyone know if there is a third-party tool, or maybe Excel 2007 has this feature natively, that would allow me to retrieve the latest stock quotes for a dozen stocks each time the spreadsheet was opened? I haven't been able to find a charting service that has the kind of charts I want, so I will be creating them in Excel from daily quotes. Would like to avoid keyentering daily closing stock prices, if possible. Thanks, Tom goto xltraders-subscribe@yahoogroups.com and look in the files section. There are several free files. I have a couple of free file...

Public Calender access rights.
I setup a public calendar for a small office so everyone can check it anytime they want to see who is scheduled for vacation, staff meetings, etc. Only the administrator has the ability to add and edit items, everyone else has viewing only. However, when a user goes into the public calendar via Outlook they can open and item and attempt to change it, but the system will not allow it because of their access rights being limited. What I would like to happen is as soon as they click on a calendar item, the access is denied immediately instead of letting them into it, changing the item an...

Access 2007: How to run reports from forms???
Greetings, I designed a form and ran the macro button wizard to create a button (with macro) to run my report. This worked fine, with my report output also containing buttons to exit and print the report. I later wanted to add validation to check if the report was empty, so I removed the button created by the wizzard and created my own, adding my own vba code. The problem lies I can only run the report using 'DoCmd.OpenReport "rptStudentClassification", acViewPreview' but this is a preview mode only and therefore cannot use buttons present on the report. How do i ru...