使用参数调用 VBScript [英] Calling a VBScript using arguments

查看:25
本文介绍了使用参数调用 VBScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个 VBScript 启动另一个 VBScript,同时将第一个参数传递给第二个.我得到了如何在第二个脚本上接收参数的部分,但是我不知道如何在第一个 VBScript 中调用它.这是我目前在第一个中的内容:

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:

脚本:C:\Argument Test 1.vbs
行:2
字符:1
错误:对象需要objShell"
代码:800A01A8
来源:Microsoft VBScript 运行时错误

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!

推荐答案

你需要用

Set objShell = CreateObject("WScript.Shell")

在你可以使用它的 .Run 方法之前.

before you can use its .Run method.

此外,VBScript 不会扩展字符串内的变量,因此您需要将参数连接到命令字符串的其余部分:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆