带有长参数的运行命令上的 vbscript 错误 [英] vbscript error on run command with long argument

查看:18
本文介绍了带有长参数的运行命令上的 vbscript 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 vbs 上执行一个脚本

我用这个脚本运行 program.exe 没有问题

objShell.Run("%SystemDrive%\temp\program.exe")

但是该程序可以支持静默安装的争论

我在 cmd 上手动运行以下命令

<前>%SystemDrive%\temp\program.exe/s/v"MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+!%temp%\install.log IP=False CFG="CFG_GRP"ICG="ICG_GRP" REBOOT=Force/qn""

所以我把这个命令放在脚本上但得到异常错误')'

objShell.Run("%SystemDrive%\temp\program.exe/s/v"MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+!%temp%\install.log IP=False CFG="CFG_GRP" ICG="ICG_GRP" REBOOT=Force/qn""")

有什么想法吗?

解决方案

试试这个

Command = "cmd/c %SystemDrive%\temp\program.exe/s/v""MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+!%temp%\install.log IP=False CFG=""CFG_GRP"" ICG=""ICG_GRP"" REBOOT=Force/qn"""""objShell.Run 命令

objShell.Run "cmd/c %SystemDrive%\temp\program.exe/s/v""MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+!%temp%\install.log IP=False CFG=""CFG_GRP"" ICG=""ICG_GRP"" REBOOT=Force/qn"""""

无论哪种方式都可以解决问题是格式不正确的字符串.

因为引号 " 在字符串中使用时表示字符串的开始和结束,所以必须通过将它们加倍 "" 来转义,否则 VBScript 会认为它是字符串的结尾并抛出语法错误.

I need execute a script on vbs

I have no problem run the program.exe with this script

objShell.Run("%SystemDrive%\temp\program.exe")

However the program can support the arguement for silent installation

I run the following command manually on cmd is

%SystemDrive%\temp\program.exe /s /v"MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+! %temp%\install.log IP=False CFG="CFG_GRP" ICG="ICG_GRP" REBOOT=Force /qn""

so I put this command on the script but get exception error ')'

objShell.Run("%SystemDrive%\temp\program.exe /s /v"MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+! %temp%\install.log IP=False CFG="CFG_GRP" ICG="ICG_GRP" REBOOT=Force /qn""")

any idea?

解决方案

Try this

Command = "cmd /c %SystemDrive%\temp\program.exe /s /v""MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+! %temp%\install.log IP=False CFG=""CFG_GRP"" ICG=""ICG_GRP"" REBOOT=Force /qn"""""
objShell.Run Command

or

objShell.Run "cmd /c %SystemDrive%\temp\program.exe /s /v""MS=1.1.1.1 SF= %SystemDrive%\temp\cert.ssl -l*v+! %temp%\install.log IP=False CFG=""CFG_GRP"" ICG=""ICG_GRP"" REBOOT=Force /qn"""""

Either way will work the issue is the incorrectly formed string.

Because quotes " denote the start and end of a string when used inside a string they have to be escaped by doubling them "", otherwise VBScript will think it's the end of the string and throw a syntax error.

这篇关于带有长参数的运行命令上的 vbscript 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆