maihabunash
maihabunash

Reputation: 1702

why CMD window get the parameter name and not the value of parameter

I need to run the following command on CMD window under C:\Program Files\CONNECTION

 connect  "user_vip"

so write short VB script that perform this action

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
USERC = """user_vip"""
Wscript.Echo USERC
oShell.run "cmd /k CD C:\Program Files\CONNECTION & connect USERC   " ,1 , true

After I run the VB script I see the following from CMD window

connect USERC   

and not as I expected to see:

 connect  "user_vip"

why USERC parameter in oShell.run not get the real value - "user_vip" ??

Upvotes: 0

Views: 131

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38755

VBScript does not interpolate variable content into string literals and a path containing blanks/spaces in a shell command needs quotes (" escaped as "") so change

oShell.run "cmd /k CD C:\Program Files\CONNECTION & connect USERC   " ,1 , true

to

oShell.run "cmd /k CD ""C:\Program Files\CONNECTION"" & connect " & USERC, 1, True

Update wrt comment:

>> userc = "abc"
>> WScript.Echo "cmd /k CD ""C:\Program Files\CONNECTION"" & connect " & USERC
>>
cmd /k CD "C:\Program Files\CONNECTION" & connect abc

Upvotes: 3

Related Questions