batch-file - 如何在批处理文件中设置参数等于VB6变量

标签 batch-file vb6 vbscript imagemagick dos

在我的批处理文件中,我调用 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/

相关文章:

batch-file - 以管理员身份从另一个批处理文件运行一个批处理文件

node.js - Node JS,检测生产环境

vb6 - VB6是否支持无符号数据类型?

java - 从 Java 随机访问 VB6 二进制数据

vbscript - 使用VBS保存网页上的可见文本

xml - 为什么我能够从一个 XML 节点获取文本,但不能从其同级节点获取文本?

batch-file - 在ubuntu终端中执行一系列命令

batch-file - SendTo 文件夹的 7zip SFX 批处理

arrays - ReDim在Visual Basic 6中保留为多维数组

postgresql - 使用 WShell.Script Run 启动批处理文件时 VBScript 挂起