我需要在C:\ Program Files \ CONNECTION
下的CMD窗口上运行以下命令 connect "user_vip"
所以编写执行此操作的简短VB脚本
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
运行VB脚本后,我在CMD窗口中看到以下内容
connect USERC
并不像我预期的那样:
connect "user_vip"
为什么 oShell.run 中的 USERC 参数未获得实际值 - “user_vip”?
答案 0 :(得分:3)
VBScript不会将变量内容插入到字符串文字中,并且shell命令中包含空格/空格的路径需要引号(“转义为”“)所以更改
oShell.run "cmd /k CD C:\Program Files\CONNECTION & connect USERC " ,1 , true
到
oShell.run "cmd /k CD ""C:\Program Files\CONNECTION"" & connect " & USERC, 1, True
更新评论:
>> userc = "abc"
>> WScript.Echo "cmd /k CD ""C:\Program Files\CONNECTION"" & connect " & USERC
>>
cmd /k CD "C:\Program Files\CONNECTION" & connect abc