【问题标题】:Passing an array from a VBScript to another VBScript将数组从 VBScript 传递到另一个 VBScript
【发布时间】:2017-03-28 04:30:38
【问题描述】:

我想知道是否可以将数组从 VBScript 传递给另一个。

实际上我想要实现的是将二维数组传递给另一个 VBScript。

我打算做的是,我运行一个脚本将文件复制到本地计算机中的特定文件夹,这是软件部署的一部分(不需要安装)。

但是因为我要对多个软件执行此操作,所以我正在使用我的函数创建一个通用模板。

我现在陷入的困境是创建快捷方式。 (用于创建多个快捷方式的模板)。

所以我打算发送一个二维数组。

这是一个例子:

Application Group 1
Installation Scripts Starts
'
'
Some Code
'
'
After files of Applications are copied
'
'
Run Shortcut Deployment(send a 2D of array with it)
'
'
Shortcuts Deployed
'
'
Installation Scripts Ends

然后

Application Group 2
Installation Scripts Starts
'
'
Different code
'
'
Run Same Shortcut Deployment(but a different 2D of array with it)
'
'
Shortcuts Deployed
'
'
Installation Scripts Ends

例如 (0,0) 将包含快捷方式名称 & (0,1) 将包含应用程序路径。 (1,0) 将包含另一个应用程序的快捷方式名称,而 (1,1) 将包含另一个应用程序路径。

等等……

有没有办法做这样的事情?

【问题讨论】:

  • 没有优雅的方法可以做到这一点。为什么不将所有这些信息发送为command line arguments
  • 知道如何通过命令行参数实现这一点吗?
  • 一般可以通过多种方式实现。如果脚本进程将同时运行(第一个运行第二个并等待它结束),那么第一个脚本中的数组(或任何其他变量)可以通过多进程环境直接从第二个脚本访问。如果他们一个接一个地启动,那么应该首先序列化数组以作为字符串传递。另一种方法是实现 Include 功能,这样快捷部署脚本文件可以在另一个脚本中运行。

标签: arrays vbscript parameter-passing


【解决方案1】:

一个简单的演示

script1.vbs

Dim objShell

varShort1 = "Shortcut1"
varShort2 = "Shortcut2"
varApp1 = "C:\path1"
varApp2 = "C:\path2"

Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "script2.vbs " & varShort1 & " " & varApp1 & " " & varShort2 & " " & varApp2, True
Set objShell = Nothing

wscript.quit

script2.vbs

Set args = Wscript.Arguments

For Each arg In args
  Wscript.Echo arg
Next

wscript.quit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2015-05-01
    • 1970-01-01
    • 2012-07-01
    相关资源
    最近更新 更多