Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Passing variables between VBScripts when calling one from another

Posted on 2011-02-17
6
695 Views
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

0
Comment
Question by:ob1_
  • 3
  • 2
6 Comments
 
LVL 70

Accepted Solution

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

Chris
0
 
LVL 53

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.

~bp
0
 
LVL 6

Author Comment

by:ob1_
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?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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.

Chris
0
 
LVL 6

Author Comment

by:ob1_
ID: 34918637
can i pass an entire array as an argument?
0
 
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 ;)

Chris
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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