Passing variables between VBScripts when calling one from another

Posted on 2011-02-17
Last Modified: 2012-05-11
If I call 1 VBScript from another using the code below, can I set variables in the "called" script with information and variables from the originating script?
Dim strFileName
strFileName =  Chr(34) & "C:\Program Files\PIDX\compact.vbs" & Chr(34)

Set WSHShell = CreateObject("WScript.Shell") 
WSHShell.Run "wscript " & strFileName, , True

Open in new window

Question by:ob1_
  • 3
  • 2
LVL 70

Accepted Solution

Chris Dent earned 400 total points
ID: 34916966
Only by passing arguments and handling those in the called script.

LVL 51

Assisted Solution

by:Bill Prew
Bill Prew earned 100 total points
ID: 34917053
The other option, if there is a lot of context information that needs to be passed would be write out a CSV, INI, or XML file from the first script, that can be read by the second script to establish context.


Author Comment

ID: 34917281
if i Dim an array in the first script and load it with information, can I then use the array in the called script as if it were still in the 1st script?

or is there something special I need to do to bring the array over?
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

LVL 70

Expert Comment

by:Chris Dent
ID: 34917296

Nope, the two scripts are isolated from each other. Variables you declare and use in one will not be available in the other.


Author Comment

ID: 34918637
can i pass an entire array as an argument?
LVL 70

Expert Comment

by:Chris Dent
ID: 34919308
Not as an array, VbScript doesn't really understand that kind of complexity. You could pass it like this:

otherscript.vbs /p1:"value1,value2,value3"

Then inside otherscript:
Dim arrParam1 : arrParam1 = Split(WScript.Arguments.Named("p1"), ",")

Open in new window

I'd test that though, I don't do all that much with VbScript anymore. I should try and take this opportunity to convert you to PowerShell ;)


Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now