使用参数调用VBScript [英] Calling a VBScript using arguments
问题描述
我正在尝试获取一个VBScript来启动另一个VBScript,同时将参数从第一个传递到第二个.我已经了解了如何在第二个脚本中接收参数,但是我不知道如何在第一个VBScript中调用该参数.这是我当前在第一个数据库中的内容:
arg1 = "MyArgument"
objShell.Run "ArgumentTest2.vbs arg1"
当我运行此脚本时,它会给我错误消息:
脚本:C:\ Argument Test 1.vbs
行:2
字符:1
错误:对象必填'objShell'
代号:800A01A8
来源:Microsoft VBScript运行时错误
任何帮助将不胜感激!谢谢!
您需要使用
arg1 = "MyArgument"
objShell.Run "ArgumentTest2.vbs arg1"
初始化objShell
Set objShell = CreateObject("WScript.Shell")
,然后才能使用其.Run
方法.
此外,VBScript不会在字符串内扩展变量,因此您需要将参数连接到命令字符串的其余部分:
objShell.Run "ArgumentTest2.vbs " & arg1
请注意,如果令牌中包含空格,则需要将其用双引号引起来:
arg1 = "My Argument"
objShell.Run "ArgumentTest2.vbs """ & arg1 & """"
I am trying to get a VBScript to launch another VBScript while passing an argument from the first one to the second one. I got the part of how to receive the argument on the second script, however I have no clue how to call it within the first VBScript. Here is what I currently have in the first one:
arg1 = "MyArgument"
objShell.Run "ArgumentTest2.vbs arg1"
When I run the this script, it gives me the error message:
Script: C:\Argument Test 1.vbs
Line: 2
Char: 1
Error: Object required 'objShell'
Code: 800A01A8
Source: Microsoft VBScript runtime error
Any help would be greatly appreciated! Thanks!
You need to initialize objShell
with
Set objShell = CreateObject("WScript.Shell")
before you can use its .Run
method.
Also, VBScript doesn't expand variables inside strings, so you'll need to concatenate your argument to the rest of the command string:
objShell.Run "ArgumentTest2.vbs " & arg1
Note that you'll need to put tokens in double quotes if they contain spaces:
arg1 = "My Argument"
objShell.Run "ArgumentTest2.vbs """ & arg1 & """"
这篇关于使用参数调用VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!