Solved

Passing variables between VBScripts when calling one from another

Posted on 2011-02-17
6
693 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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb script  to start the services is not working 4 37
If not exist vbs error 4 40
Using VB6 to write Excel Spreadsheets - 5 40
fso.FolderExists("\\server\HiddenFolder$") 4 52
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…
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

15 Experts available now in Live!

Get 1:1 Help Now