?
Solved

Passing an argument which includes double quotes to wscript.echo

Posted on 2010-04-08
19
Medium Priority
?
1,752 Views
Last Modified: 2012-05-09
I regularly use a script to connect to various servers. The script is run in the following manner:

myscript.vbs <TYPE> <SERVERIPADDRESS> <USERNAME> <PASSWORD>

However when the password includes double quotes, they fail to display. This is the code I use to display the username and password:

wscript.echo "Username: " & args.item(2) & "  Password: " & args.item(3)

Without changing the script, is there a way I can pass the double quotes? I've already tried double quote 1, 2 and 3 times, with a preceeding \ and using chr(34). And at best ended up with \ or chr(34) displaying in my popup.
0
Comment
Question by:pazza98
  • 6
  • 6
  • 4
  • +3
19 Comments
 
LVL 15

Expert Comment

by:StealthyDev
ID: 30110090
use double-double quote - ""
0
 
LVL 31

Expert Comment

by:merowinger
ID: 30110238
@senthurpandian: does not work
0
 

Author Comment

by:pazza98
ID: 30110258
Then I end up with abcde where I should get "abcde". See below.

---------------------------
Windows Script Host
---------------------------
Username: administrator  Password: abcde
---------------------------
OK  
---------------------------
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
LVL 31

Expert Comment

by:merowinger
ID: 30110620
quotes are really the last characters you should use in your password when using wscript.exe or cscript.exe ;)
I get all characters passed to the script..but not quotes!
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30111415
Following on merowinger...

If you must allow quotes, I suggest that you designate a particular character/character sequence to stand in for them, and then set up your VBS to do the replacement in code.
0
 
LVL 31

Expert Comment

by:merowinger
ID: 30111871
Exactly e.g This would replace the ~ with a quote

myscript.vbs Username Passw~rd

strPassword = Replace(Wscript.Arguments(1),"~",chr(34))

0
 

Author Comment

by:pazza98
ID: 30113480
However any character or string I might use in replacement,  could also be something I might use in the password. I often don't have a choice about the password and I'm not in a position to change the script. Is what I'm asking impossible?
0
 
LVL 31

Assisted Solution

by:merowinger
merowinger earned 600 total points
ID: 30113657
Yes you right and yes it's almost impossible!
You could also input the password by reading it from an textfile. This would work
0
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 600 total points
ID: 30113881
Or you can make the sequence for doublequote be more than one character:

strPassword = Replace(Wscript.Arguments(1),"@^~#",chr(34))

While it is conceivable that a user may want to use a tilde in a password, it seems unlikely to me that a user would want to have the characters @^~# as a real sequence in the password :)
0
 
LVL 31

Expert Comment

by:merowinger
ID: 30114122
@matthewspatrick: Bill Gates for sure :P
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30120353
:)
0
 
LVL 14

Expert Comment

by:Psy053
ID: 30176432
Why not have the script prompt for the password instead?

strPassword = InputBox("Please enter your password")
wscript.echo "Username: " & args.item(2) & "  Password: " & strPassword

0
 

Author Comment

by:pazza98
ID: 30192607
@Psy053

I think I stated earlier that I'm not in a position to make any changes to the script. Also, the point is to receive an automatic reminder of the password in the popup, not have it entered automatically. In any case it wouldn't be very automatic if I had to type it into a prompt first.
0
 
LVL 31

Expert Comment

by:merowinger
ID: 30193028
I don't see more options, as the less possibilities which we can deliver are furthermore not feasible caused of restrictions on editing the script or changeing the password
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30198231
pazza98,

If you want to be able to accommodate " in the password, you are going to have to change the script.  merowinger and I have demonstrated a very, very simple way to do that.

It may not have been the answer you wanted to hear, but it is the right answer.

Patrick
0
 

Author Comment

by:pazza98
ID: 30203481
Without changing the script, is there a way I can pass the double quotes?

Without an answer to this question I can't really award points. There's no point in awarding points to an answer of "there is no way".

Thanks for the suggestions.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30204528
>>Without an answer to this question I can't really award points. There's no point in awarding points to
>>an answer of "there is no way".

Respectfully, I disagree, and so do the EE help pages.  From http://www.experts-exchange.com/help.jsp#hs=29&hi=405


The correct answer to some questions is "You can't do that."        

Sometimes, you will get an answer that isn't what you want to  read, but it still may be the correct answer, and you should award  points to the Expert that gave you that answer.

Patrick
0
 
LVL 5

Accepted Solution

by:
AbqBill earned 800 total points
ID: 30210944
The answerers are correct. The WshArguments object is in charge of reading the script's command-line arguments, and the object always interprets the double quote character (") as an argument delimiter. There is no way to do what you want without modifying the script. Bill.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 30220551
pazza98,

Sorry that we were not able to get a more satisfying answer, and thank you for not holding that against us.  I know what it's like when the correct answer is not what you wanted :(

Patrick
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question