从VBScript将参数传递给批处理文件 [英] Passing parameters from vbscript to batch file

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

问题描述

我有传递参数通过一个VBScript来一个批处理文件的问题。
我不是在编程很好,所以我相信我只是缺少一些愚蠢的事。
反正我是用VBScript来无形地运行该批处理文件

Hi I am having an issue passing parameters through a vbscript to a batch file. I am not very good at programming so I am sure I am just missing something stupid. Anyway I am using the vbscript to invisibly run the batch file

VBScript的被称为C:\\ Program Files文件(x86)的\\脚本\\ check.vbs%S%D

The vbscript is called as "C:\Program Files (x86)\scripts\check.vbs" %S "%D"

其中%s是国家和%D是目录。

Where %S is state and %D is directory.

如果我直接调用批处理文件C:\\ Program Files文件(x86)的\\脚本\\ checkdir.bat%S%D一切工作,除了罚款有一个DOS窗口弹出而烦恼。

If I call the batch file directly as "C:\Program Files (x86)\scripts\checkdir.bat" %S "%D" everything works fine except there is a dos windows that pops up which is annoying.

所以,我环顾四周,互联网和发现这个VBScript中,可以静默方式运行批处理文件。它实际上运行它默默地但它不会将参数传递给该批处理文件。

So I looked around the internet and found this vbscript that can run a batch file silently. It does in fact run it silently however it does not pass the parameters to the batch file.

下面是VBScript的:

Here is the vbscript:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Program Files (x86)\scripts\checkdir.bat" & Chr(34), 0
Set WshShell = Nothing

我会如何传递参数?我已经搜查,但我不能拿出任何东西为我工作,我要么得到它运行错误或参数不会通过。

How would I go about passing the parameters? I have searched but I could not come up with anything that worked for me, I would either get an error on running it or the parameters would not pass.

推荐答案

假设你所呼叫的VBScript中这样...

Assuming you are calling the VBScript in this way...

wscript myscript.vbs ArgumentS ArgumentD

然后换出2号线这应该工作...

Then swapping out line 2 for this should work...

WshShell.Run """C:\Program Files (x86)\scripts\checkdir.bat"" " & WScript.Arguments.Item(0) & " """ & WScript.Arguments.Item(1) & """", 0

请注意,我假设你需要传递参数d用双引号,所以我已包括这些。在字符串中的VBScript将取代单一双引号双双引号。如果它不工作,改变WshShell.Run为wscript.echo,你应该看看到底是什么VBScript是试图通过。如果它是不完全正确,调整和WshShell.Run再试。

Note that I am assuming that you need to pass Argument D with double-quotes around it so I have included those. Inside a string VBScript will replace double-double quotes with single-double quotes. If it doesn't work, change WshShell.Run to wscript.echo and you should see exactly what VBScript is trying to pass. If it is not quite right, adjust it and try again with WshShell.Run.

祝你好运。

这篇关于从VBScript将参数传递给批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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