在 VBscript 命令中使用 SET

using SET in VBscript command

我正在尝试 运行 一个 VBscript,其中 运行 是一个命令行语句,在 cmd 行命令中包含单词 set。 VBscript 将其识别为保留字并给出错误:

Expected ')'

我在 VBScript 中尝试 运行 的命令是:

objShell.Run(appcmd set config /section:isapiFilters /-[name='JakartaXAPI'])

如何转义保留字?

Microsoft VBScript compilation error: Expected ')' 只是一个 语法错误 .

Run 方法要求它的第一个参数是 string subtype 并且给定 space 分隔的单词序列不能计算为 string.您需要用引号将其括起来 (" ")。

Run Method (Windows Script Host)

Runs a program in a new process.

Syntax

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 

Arguments

  • object WshShell object.
  • strCommand String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file.
  • intWindowStyle Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information.
  • bWaitOnReturn Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).

使用

objShell.Run "appcmd set config /section:isapiFilters /-[name='JakartaXAPI']"

appcmd = "path\to\someapp.exe"
objShell.Run appcmd & " set config /section:isapiFilters /-[name='JakartaXAPI']"