2016-05-25 2 views
-1

cmd lineコマンドでsetという単語を含むコマンドライン文を実行するVBscriptを実行しようとしています。 VBScriptが予約語としてそれを認識し、エラーを与えている:VBscriptコマンドでSETを使用する

Expected ')'

私はVBScriptで実行しようとしているコマンドは次のとおりです。

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

どのように私は予約語をエスケープすることができますか?

+1

文字列は引用符で囲む必要があります。 –

答えて

2

Microsoft VBScript compilation error: Expected ')'は、単にの構文エラーです。

Run方法があることを最初の引数を必要string subtypeし、与えられたスペース区切りの単語列が文字列ため侮れすることはできません。引用符で囲む必要があります(" ")。

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']" 
+0

本当ですか?彼らはロケット科学ではなく、VBScriptランタイムのエラーを引き起こす文字列として 'Run()'にコマンドを渡していませんでした。 [@麺はすでに2時間以上前にこれを言及している](http://stackoverflow.com/questions/37427824/using-set-in-vbscript-command#comment62360285_37427824)。 – Lankymart

+0

@Lankymartはい、本当に。 'Expected ')''は_compilation_ではなく_runtime_エラーです。 – JosefZ

+0

あなたのポイントは?私はそれがランタイムエラーだとは言わなかった。私は「VBScript Runtime」*(スクリプトエンジンを参照する)*エラーを言った。この答えは実際の問題にはほとんど関係していないと思う... 'Option Explicit'と' On Error Goto 0'はこのエラーを*(あなた自身が言った、コンパイルエラーだ) ? – Lankymart

関連する問題