我正在尝试将字符串参数从批处理文件传递到包含字符串的vbs脚本,但是出现了一些问题。我尝试了几种变体,但无法正确完成。
_execute.vbs
:
Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream(1)
Set stderr = fso.GetStandardStream(2)
stdout.Write WScript.Arguments.Item(0) & "... "
Dim objShell, oExec
Set objShell = WScript.CreateObject ("WScript.Shell")
intReturn = objShell.Run(WScript.Arguments.Item(1), 0, True)
if intReturn = 0 Then
stdout.WriteLine "Done"
Else
stderr.WriteLine "Error (Return Code: " & intReturn & ") trying to execute [" & WScript.Arguments.Item(1) & "]"
End If
第一次尝试:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:\Windows\SysWOW64\inetsrv\appcmd set site ""Default Web Site"" -name:Stream"
输出:
正在安装IIS ...尝试执行[C:\ Windows \ SysWOW64 \ inetsrv \ appcmd设置站点默认网站-名称:流]错误(返回代码:87)
第二次尝试:
install.bat
:
@echo off
cscript /nologo _execute.vbs 'Installing IIS' 'C:\Windows\SysWOW64\inetsrv\appcmd set site "Default Web Site" -name:Stream'
输出:
“正在安装... C:\ DEV_execute.vbs(8,1)(空):系统找不到指定的文件。
第三次尝试:
install.bat
:
@echo off
cscript /nologo _execute.vbs "Installing IIS" "C:\Windows\SysWOW64\inetsrv\appcmd set site ^"Default Web Site^" -name:Stream"
输出:
正在安装IIS ...尝试执行[C:\ Windows \ SysWOW64 \ inetsrv \ appcmd设置站点^ Default]时出错(返回代码:1168)
如何传递两个包含引号的字符串参数?
答案 0 :(得分:-1)
I ended up just using a single quote in the batch file
cscript /nologo _execute.vbs "Installing IIS" "C:\Windows\SysWOW64\inetsrv\appcmd set site 'Default Web Site' -name:Stream"
and replacing them with double quotes in the VBS file.
Replace(WScript.Arguments.Item(1),"'",chr(34))
It's not ideal, but it works for my uses.