Parameters VBS-多参数

Parameters VBS-多参数,parameters,vbscript,arguments,Parameters,Vbscript,Arguments,我正在创建脚本以传递一个或多个参数。脚本在一个参数下工作正常,但在多个参数下失败 这是我的代码: Set WshShell = WScript.CreateObject("WScript.Shell") strCommand = Wscript.Arguments(0) & " " & Wscript.Arguments(1) WshShell.Run(strCommand) 当我运行script.vbs记事本1时,它会工作,但当我运行script.vbs记事本时,它会失败

我正在创建脚本以传递一个或多个参数。脚本在一个参数下工作正常,但在多个参数下失败

这是我的代码:

Set WshShell = WScript.CreateObject("WScript.Shell") 
strCommand = Wscript.Arguments(0) & " " & Wscript.Arguments(1) 
WshShell.Run(strCommand)
当我运行
script.vbs记事本1
时,它会工作,但当我运行
script.vbs记事本时,它会失败


我在网上搜索并尝试使用不同的脚本,但没有一个脚本起作用,因此我需要一些帮助来帮助我进行操作。

在访问WSCript之前,您需要检查是否存在参数n。通过查看WSCript.Arguments.Count查看参数(n):

Option Explicit
Dim oWAU : Set oWAU = WScript.Arguments.Unnamed
Dim sArg1 : sArg1 = ""
Dim nArg2 : nArg2 = 1
If 1 <= oWAU.Count Then sArg1 = oWAU(0)
If 2 <= oWAU.Count Then nArg2 = CLng(oWAU(1))
WScript.Echo sArg1, nArg2

现在我得到了:如果WScript.Arguments.Count=0,那么WScript.Echo“缺少参数”WScript.Quit 1 end如果设置WshShell=WScript.CreateObject(“WScript.Shell”)strCommand=WScript.Arguments(0)对于WScript.Arguments.Count strCommand=strCommand&&WScript.Arguments(I)下一个WshShell.Run(strCommand)当我运行cscript script.vbs记事本1时,它会使我的下标超出范围cscript script.vbs记事本工作正常。有什么想法吗?
args.vbs notepad
notepad 1

args.vbs notepad 4
notepad 4