Re: Accessing full command line or parameters WITH QUOTES

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Bennett" <Bennett@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0AF8A657-356A-4F70-B779-901DF2B58ECA@xxxxxxxxxxxxxxxx
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
--


.



Relevant Pages

  • Re: Accessing full command line or parameters WITH QUOTES
    ... The problem is that VBScript doesn't allow access to the full command line ... rebuild the parameters with the quotes inserted properly. ... as one argument to your script, ... following will run the php script (assuming php is ...
    (microsoft.public.scripting.vbscript)
  • Re: Accessing full command line or parameters WITH QUOTES
    ... The problem is that VBScript doesn't allow access to the full command line ... rebuild the parameters with the quotes inserted properly. ... what is that escape? ... as one argument to your script, ...
    (microsoft.public.scripting.vbscript)
  • Re: Launch chm file on WS within HTML
    ... escape another. ... However, in Java Script, the rules are ... The command line cd ... |> | and only surrounded the file path with two double quotes. ...
    (microsoft.public.scripting.wsh)
  • Re: Accessing full command line or parameters WITH QUOTES
    ... rebuild the parameters with the quotes inserted properly. ... command line arguments. ... as one argument to your script, ... It follows that the command processor preserves at least ...
    (microsoft.public.scripting.vbscript)
  • Applescript and Autoformat (search and replace), Word 2004
    ... script that will take care of a recurring editing issue with nested ... quotes to double quotes, ... set oldauto2 to auto format as you type replace quotes ... set auto format as you type replace quotes to false ...
    (microsoft.public.mac.office.word)