Passing an argument beginning with //
(e.g. //ABC
) to a VBS file (Wscript) results in an "Unknown Option" error.
How can I catch and handle this error?
Passing an argument beginning with //
(e.g. //ABC
) to a VBS file (Wscript) results in an "Unknown Option" error.
How can I catch and handle this error?
Look at
Option Explicit
Dim i
For i = 0 To WScript.Arguments.Length - 1
WScript.Echo i, WScript.Arguments(i)
Next
output:
cscript 45765234.vbs one two three /a /b /c //D \\ABC
0 one
1 two
2 three
3 /a
4 /b
5 /c
6 \\ABC
e:\work\proj\soa\tmp
cscript 45765234.vbs one two three /a /b /c //D //ABC
Eingabefehler: Es wurde die unbekannte Option "//ABC" angegeben.
and:
cscript
Syntax: CScript Skriptname.Erweiterung [Option...] [Argumente...]
Optionen:
//B Batch-Modus: Zeigt keine Skriptfehler und Aufforderungen an
//D Aktives Debuggen aktivieren
//E:engine Modul zum Ausführen des Skripts verwenden
//H:CScript Ändert den Standardskripthost auf CScript.exe um
//H:WScript Ändert den Standardskripthost auf WScript.exe um (Standard)
//I Interaktiver Modus (Standard; Gegenteil von //B)
//Job:xxxx Führt einen WSF-Auftrag aus
//Logo Zeigt das Logo an (Standard)
//Nologo Zeigt kein Logo an: Bei Ausführung wird kein Banner angezeigt
//S Speichert die aktuellen Befehlszeilenoptionen für diesen Benutzer
//T:nn Timeout in Sekunden: Maximale Zeit, die ein Skript laufen darf
//X Führt das Skript im Debugger aus
//U Unicode für umgeleitete E/A-Vorgänge von der Konsole aus verwenden
And see: You can't use // or catch them in the script, because they are handled by the host (cscript.exe, wscript.exe). Using \, however, causes no problems.