传递变量从 - VBScript中到批处理文件带参数 [英] Passing-variable-from-vbscript-to-batch-file with arguments
问题描述
请如何从这块VBS的做呼应时传递INP变量到我的一批名为job.bat?事实上(回声%2)job.bat,我注意到,INP不能正常通过。提示命令视图INP,而不是从VBS检索到的值。谢谢
对于每个listElement在xmlDoc.selectNodes(文档/列表/列表)
MSGBOXTOTO
INP = listElement.selectSingleNode(进入)。文本
OUT = listElement.selectSingleNode(输出)。文本
杰顿= listElement.selectSingleNode(令牌)。文本 昏暗的壳
一套SHELL = CREATEOBJECT(wscript.shell)
shell.runjob.bat文件** ** INP
一套SHELL =什么
下一个
我认为你正在寻找这是什么。
shell.runjob.batargfile.ext与& INP
不过,由于安斯加尔Wiechers 指出,这是一个潜在的严重安全漏洞,作为一个背信弃义制作的XML文件能运行任意命令。要封装您的批处理文件参数和prevent意想不到的后果,考虑切换到 Shell.Application
对象的的ShellExecute方法。
对于每个listElement在xmlDoc.selectNodes(文档/列表/列表) MSGBOXTOTO
INP = listElement.selectSingleNode(进入)。文本
OUT = listElement.selectSingleNode(输出)。文本
杰顿= listElement.selectSingleNode(令牌)。文本 一套SHELL =的CreateObject(Shell.Application)
shell.ShellExecutejob.bat,文件与& INP,路径\\为\\ batfile \\,运行方式,1
一套SHELL =什么下一个
Please how to pass the 'inp" variable from this piece of vbs to my batch named job.bat? Indeed when doing echoing (echo %2) from job.bat, i notice that the inp is not passed properly. prompt command views inp and not the value retrieved from vbs. Thanks
For Each listElement In xmlDoc.selectNodes("document/Lists/list")
msgbox "toto"
inp=listElement.selectSingleNode("entry").text
out= listElement.selectSingleNode("output").text
jeton= listElement.selectSingleNode("token").text
dim shell
set shell=createobject("wscript.shell")
shell.run "job.bat ""a file"" **inp** "
set shell=nothing
Next
I think what you're looking for is this.
shell.run "job.bat ""argfile.ext"" " & inp
However, as Ansgar Wiechers points out, this is a potentially severe security hole, as a treacherously crafted XML file could run arbitrary commands. To encapsulate your batch file arguments and prevent unintended consequences, consider switching to the Shell.Application
object's ShellExecute method.
For Each listElement In xmlDoc.selectNodes("document/Lists/list")
msgbox "toto"
inp = listElement.selectSingleNode("entry").text
out = listElement.selectSingleNode("output").text
jeton = listElement.selectSingleNode("token").text
set shell=CreateObject("Shell.Application")
shell.ShellExecute "job.bat", """a file"" " & inp, "path\to\batfile\", "runas", 1
set shell=nothing
Next
这篇关于传递变量从 - VBScript中到批处理文件带参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!