在我的批处理文件中,我调用 VBScript 并向其传递 3 个参数。参数为“IPADDRESS”“PicName”和“Storage”,如下所示:
批处理文件:
set Pathname="C:\User\username\locationOfFile
cd /d %Pathname%
cscript.exe C:\User\username\locationOfFile\myScript.vbs IPADDRESS PicName Storage
在我的VB6程序中,定义了参数值。
例如,IPADDRESS = "170.190.xxx.xxx"
有没有办法让批处理文件读取并使用基于 VB6 表单内的声明的 IPADDRESS 值?变量 IPADDRESS、PicName 和 Storage 将根据 VB6 程序与之通信的外部应用程序不断变化,因此我无法在批处理中静态设置它 ( ....\myScript.vbs 170.190.xxx.xxx pic1 C:\存储)
我的 VBScript 如下:
Option explicit
if WScript.Arguments.Count <> 3 then
WScript.Echo "Missing parameters"
else
Dim imageMagick
Set imageMagick = CreateObject("ImageMagickObject.MagickImage.1")
Dim cam_add
Dim annotate
Dim filename
Dim cmd
Dim WshShell
Dim return
cam_add = """http://" & WScript.Arguments(0) &"/image"""
annotate = """" & WScript.Arguments(1) & " - """ '& Date
filename = """" & WScript.Arguments(2) & WScript.Arguments(1) & ".jpg"""
cmd = "convert " & cam_add & " -fill gold -pointsize 45 -gravity southwest -annotate 0x0+25+25 " & annotate & " -trim +repage -verbose " & filename
WScript.Echo cmd
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Program Files\ImageMagick-6.8.0-Q16\"
return = WshShell.Run(cmd)
end if
总而言之,我需要将批处理设置为:
cscript.exe C:\User\用户名\locationOfFile\myScript.vbs IPADDRESS PicName 存储
因此可以根据我的 VB6 表单中的设置来使用参数值。
最佳答案
如果你要:
shell "the.bat " & IPADDRESS & " " & PicName & " " & Storage
然后在 the.bat
中,每个空格分隔的参数都可以通过 %N
获得,其中 N
是序数;因此 %1
将包含 IPADDRESS
的值,%2
将包含 PicName
的值,依此类推。
然后转发到 VBScript:
cscript.exe C:\User\username\locationOfFile\myScript.vbs %1 %2 %3
(如果任何变量包含空格,则需要在传递给bat文件之前“引用”它们)
(您也可以在 VB6 中使用 chdir(..)
,然后直接运行 CScript)
关于batch-file - 如何在批处理文件中设置参数等于VB6变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13972582/