Hi...
I posted this before, but probably didn't explain my self well...

I need to have a script that declares and sets a value for some vb
variables, and want to have the value in these variables available in other
script...

Here is what I do :
I have a master script that calls other scripts...
1st script called from master script, it declares and sets values for some
variables ...
ex : Public appver1
appver1 = "V9_4_2"

2nd script called from master script would use the variables set in 1st
script to do execute actions with it...
ex : WshEnv("Var1") = appver1

How can this be done ...
The value is "appver1" is not necessary outside of the vb environment...
Reason is that 1st script will be modified by a lot of people, but don't
want them to modify other script...

Thanks very much !!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting
www.formationhy.com
Houman@formationhy.com

Re: Variables from one script to another by Joe

Joe
Mon Jan 19 09:47:43 CST 2004

Hi,

"Houman Yahyaei" <news@formationhy.com> wrote in message
news:#MQPO$p3DHA.1704@tk2msftngp13.phx.gbl...
| Hi...
| I posted this before, but probably didn't explain my self well...
|
| I need to have a script that declares and sets a value for some vb
| variables, and want to have the value in these variables available in
other
| script...
|
| Here is what I do :
| I have a master script that calls other scripts...
| 1st script called from master script, it declares and sets values for some
| variables ...
| ex : Public appver1
| appver1 = "V9_4_2"
|
| 2nd script called from master script would use the variables set in 1st
| script to do execute actions with it...
| ex : WshEnv("Var1") = appver1
|
| How can this be done ...
| The value is "appver1" is not necessary outside of the vb environment...
| Reason is that 1st script will be modified by a lot of people, but don't
| want them to modify other script...
|
| Thanks very much !!!
|
| --
| --
| Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
| IT Training and Consulting
| www.formationhy.com
| Houman@formationhy.com

As a script, VBS has no ability to create data sinks, as such. There are
four basic methods to pass data among separate scripts:

1) Primary/secondary scripts run other scripts with data arguments and/or
get limited return through the Quit long integer code.

2) Primary/secondary scripts create session environmental variable(s) that
can be accessed from other scripts.

3) Primary/secondary scripts create temporary file(s) that can be accessed
from other scripts.

4) Michael Harris' IePipe solution:
Primary script creates an Ie.App window which does not have to be set as
visible. It can contain both data variables and embedded routines for the
secondary scripts. Secondary scripts get Ie.App object instance through the
ShellApp.Windows object collection and use the nominal window as a singleton
object instance to pass data back and forth through variables or run common
routines.

Joe Earnest



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03



Re: Variables from one script to another by Houman

Houman
Mon Jan 19 12:36:08 CST 2004

Could you explain a bit more number 2 and 4...

They both seem interesting...

Thanks !!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting
www.formationhy.com
Houman@formationhy.com

"Joe Earnest" <joeearnestNO@SPAMqwest.netPLEASE> wrote in message
news:%23alhQKq3DHA.3360@tk2msftngp13.phx.gbl...
> Hi,
>
> "Houman Yahyaei" <news@formationhy.com> wrote in message
> news:#MQPO$p3DHA.1704@tk2msftngp13.phx.gbl...
> | Hi...
> | I posted this before, but probably didn't explain my self well...
> |
> | I need to have a script that declares and sets a value for some vb
> | variables, and want to have the value in these variables available in
> other
> | script...
> |
> | Here is what I do :
> | I have a master script that calls other scripts...
> | 1st script called from master script, it declares and sets values for
some
> | variables ...
> | ex : Public appver1
> | appver1 = "V9_4_2"
> |
> | 2nd script called from master script would use the variables set in 1st
> | script to do execute actions with it...
> | ex : WshEnv("Var1") = appver1
> |
> | How can this be done ...
> | The value is "appver1" is not necessary outside of the vb environment...
> | Reason is that 1st script will be modified by a lot of people, but don't
> | want them to modify other script...
> |
> | Thanks very much !!!
> |
> | --
> | --
> | Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
> | IT Training and Consulting
> | www.formationhy.com
> | Houman@formationhy.com
>
> As a script, VBS has no ability to create data sinks, as such. There are
> four basic methods to pass data among separate scripts:
>
> 1) Primary/secondary scripts run other scripts with data arguments and/or
> get limited return through the Quit long integer code.
>
> 2) Primary/secondary scripts create session environmental variable(s)
that
> can be accessed from other scripts.
>
> 3) Primary/secondary scripts create temporary file(s) that can be
accessed
> from other scripts.
>
> 4) Michael Harris' IePipe solution:
> Primary script creates an Ie.App window which does not have to be set as
> visible. It can contain both data variables and embedded routines for the
> secondary scripts. Secondary scripts get Ie.App object instance through
the
> ShellApp.Windows object collection and use the nominal window as a
singleton
> object instance to pass data back and forth through variables or run
common
> routines.
>
> Joe Earnest
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03
>
>



Re: Variables from one script to another by Joe

Joe
Mon Jan 19 15:41:29 CST 2004

Hi again,

"Houman Yahyaei" <news@formationhy.com> wrote in message
news:OmT0yrr3DHA.2460@TK2MSFTNGP10.phx.gbl...
| Could you explain a bit more number 2 and 4...
|
| They both seem interesting...
|
| Thanks !!!
|
| --
| --
| Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
| IT Training and Consulting
| www.formationhy.com
| Houman@formationhy.com
|
| "Joe Earnest" <joeearnestNO@SPAMqwest.netPLEASE> wrote in message
| news:%23alhQKq3DHA.3360@tk2msftngp13.phx.gbl...
| > Hi,
| >
| > "Houman Yahyaei" <news@formationhy.com> wrote in message
| > news:#MQPO$p3DHA.1704@tk2msftngp13.phx.gbl...
| > | Hi...
| > | I posted this before, but probably didn't explain my self well...
| > |
| > | I need to have a script that declares and sets a value for some vb
| > | variables, and want to have the value in these variables available in
| > other
| > | script...
| > |
| > | Here is what I do :
| > | I have a master script that calls other scripts...
| > | 1st script called from master script, it declares and sets values for
| some
| > | variables ...
| > | ex : Public appver1
| > | appver1 = "V9_4_2"
| > |
| > | 2nd script called from master script would use the variables set in
1st
| > | script to do execute actions with it...
| > | ex : WshEnv("Var1") = appver1
| > |
| > | How can this be done ...
| > | The value is "appver1" is not necessary outside of the vb
environment...
| > | Reason is that 1st script will be modified by a lot of people, but
don't
| > | want them to modify other script...
| > |
| > | Thanks very much !!!
| > |
| > | --
| > | --
| > | Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
| > | IT Training and Consulting
| > | www.formationhy.com
| > | Houman@formationhy.com
| >
| > As a script, VBS has no ability to create data sinks, as such. There
are
| > four basic methods to pass data among separate scripts:
| >
| > 1) Primary/secondary scripts run other scripts with data arguments
and/or
| > get limited return through the Quit long integer code.
| >
| > 2) Primary/secondary scripts create session environmental variable(s)
| that
| > can be accessed from other scripts.
| >
| > 3) Primary/secondary scripts create temporary file(s) that can be
| accessed
| > from other scripts.
| >
| > 4) Michael Harris' IePipe solution:
| > Primary script creates an Ie.App window which does not have to be set as
| > visible. It can contain both data variables and embedded routines for
the
| > secondary scripts. Secondary scripts get Ie.App object instance through
| the
| > ShellApp.Windows object collection and use the nominal window as a
| singleton
| > object instance to pass data back and forth through variables or run
| common
| > routines.
| >
| > Joe Earnest

Torgeir Bakken explained #2 in his response to your first post, though you
may not have understood the context. (Torgeir's earlier response inline.)

---
Hi

As long as the main script is the one that starts the other scripts, using
the
process environment will work. Create the two scripts below and run the main
script to see this (if you change the name/path of C:\SecondScript.vbs,
update
the main script's Run statement accordingly).


-------------------- Main script --------------------

Set Wshshell = CreateObject("WScript.Shell")

Set oProcessEnv = Wshshell.Environment("PROCESS")

Appvar1 = "abcxyz"
oProcessEnv("NameApp1") = Appvar1

Wshshell.Run "wscript.exe C:\SecondScript.vbs", 1, False



---------------- C:\SecondScript.vbs ----------------

Set Wshshell = CreateObject("WScript.Shell")

MsgBox "Content off NameApp1 (variant 1): " _
& Wshshell.ExpandEnvironmentStrings("%NameApp1%")

Set oProcessEnv = Wshshell.Environment("PROCESS")
MsgBox "Content off NameApp1 (variant 2): " & oProcessEnv("NameApp1")
---



For #4, take a look the thread with Michael Harris' original post:

http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&newwindow=1&safe=off&th=819e016807d6b05&rnum=8

and subsequent threads (a Google advanced group search on "iepipe"):

http://www.google.com/groups?q=iepipe+group:microsoft.public.scripting.*&hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&newwindow=1&safe=off&start=0&sa=N

The script creating the first window is in MH's original post some of the
followups. The following adds a "DimNew" function that allows any script to
create a new variable or redimension an existing array, for storage in the
IE window. You don't need that function, if you define all the variables
needed in your initial dim statement. If you do want it, an explanation of
the syntax follows the code:

---
set oIe= createobject("internetExplorer.application")
oIe.navigate("about:blank")
do: wscript.sleep 50: loop until (oIe.readyState=4)
with oIe.document
.writeLn ("<html>")
.writeLn ("<head>")
.writeLn ("<script language=""vbscript"">")
.writeLn ("dim ...")

' the following is the DimNew code

.writeLn ( _
_
"function DimNew (byval vsVars)" & vbCrLf _
& "dim viVar, vpClose, vpOpen" & vbCrLf _
& "if NOT (vartype(vsVars)=vbString) then exit function" _
& vbCrLf _
& "vsVars= replace(replace(replace(vsVars, "" "", """"), _
"";"", "",""), "":"", "","")" & vbCrLf _
& "vpOpen= instr(vsVars, ""("")" & vbCrLf _
& "do while vpOpen" & vbCrLf _
& "vpClose= instr(vpOpen +1, vsVars, "")""): _
if (vpClose=0) then exit do" & vbCrLf _
& "vsVars= left(vsVars, vpOpen -1) " _
& "& replace(mid(vsVars, vpOpen, vpClose -vpOpen +1), " _
& ""","", ""|"") & mid(vsVars, vpClose +1)" & vbCrLf _
& "vpOpen= instr(vpOpen +1, vsVars, ""("")" & vbCrLf _
& "loop: vsVars= split("","" & vsVars, "","")" & vbCrLf _
& "for viVar= 1 to ubound(vsVars)" & vbCrLf _
& "on error resume next" & vbCrLf _
& "select case instr(vsVars(viVar), ""("")" & vbCrLf _
& "case 0: execute vsVars(viVar) & ""= empty""" & vbCrLf _
& "case else: vsVars(viVar)= replace(vsVars(viVar), ""|"", "","")" _
& vbCrLf _
& "execute ""redim preserve "" & vsVars(viVar)" & vbCrLf _
& "if err then err clear: execute ""redim "" & vsVars(viVar)" _
& vbCrLf _
& "end select" & vbCrLf _
& "on error goto 0" & vbCrLf _
& "next" & vbCrLf _
& "end function")

' remainder of required code

.writeLn ("...") 'your routines
.writeLn ("</script>")
.writeLn ("</head>")
.writeLn ("</html>")
end with
---

If used, the DimNew function allows new variables or dynamic arrays to be
declared, or dynamic arrays redimensioned, in the IeApp object window script
element, using the intrinsic execute statement to create new embedded HTML
global variables. The new or redimensioned variables may then be accessed
by any of the multiple scripts that use the dialog window. The syntax of
the embedded HTML DimNew function is similar to that of the intrinsic dim
statement. A single variable name or a variable list may be used. A
variable list may be delimited by commas (,), semi-colons (;) or colons (:).
Even though arrays are declared dynamically, the specific dimensions and
element upper bounds must be provided, as if declaring a static array with a
traditional dim statement. With array variables, the function will first
try to redim preserve the variable, to allow modification of the number of
elements in the final dimension. If that fails (e.g., for new variables,
dimensional changes, or non-final dimension element bound changes), then the
array will be dynamically redimensioned using redim, and any existing data
will be lost. The function provides no return. The format is:

set oScript= oIE.document.parentWindow.document.script
oScript.dimNew variable[(...)][, ...]




An example of code used in the secondary script file is the following:

---
' insert lcased <<title>> used creating IE window
set oShell= createObject("shell.application")
set oWins= oShell.windows
on error resume next
for each oWin in oWins
do
qIe= cbool(instr(lcase(typename _
(oWin.document)), "htmldocument"))
if err then exit do
if qIe then
sTitle= trim(oWin.document.title)
if err then exit do
if (lcase(sTitle)="<<title>>") then
set oIe= oWin
exit for
end if
end if
loop until true: err.clear
next
on error goto 0

with oIe.document.parentWindow.document.script
xWshVariable= .xHtmlVariable
.xHtmlVariable= value
[return=] .HtmlFunction [(arguments)]
end with
---

There may be scoping issues if trying to pass object variables, but these
issues do not arise with simple data variables. Be sure to close the IE
window when the last script is closed or when it is no longer needed
(oIe.quit).

Joe Earnest



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03



Re: Variables from one script to another by Torgeir

Torgeir
Mon Jan 19 17:55:59 CST 2004

Houman Yahyaei wrote:

> Here is what I do :
> I have a master script that calls other scripts...
> 1st script called from master script, it declares and sets values for some
> variables ...
> ex : Public appver1
> appver1 = "V9_4_2"
>
> 2nd script called from master script would use the variables set in 1st
> script to do execute actions with it...
> ex : WshEnv("Var1") = appver1
>
> How can this be done ...

Hi

Ok, now I see what you mean. You want to update the process environment of the
parent process from a child script, so any new child processes (scripts) from
that parent process will see those changes (made by subscript 1).

Updating the process environment of the parent process (from a child process)
with vbscript is not possible without using a 3rd party command line utility
that is able to set an environment variable in a foreign process (you will need
to feed it with the process ID (PID) of the foreign process). Setenv.exe found
at http://www.netexec.de/fs_lstools.html can do this, as well as ConSet.exe
found at http://home.pe.net/~fpw/freeware/ .

This will end up pretty messy, because to get the PID, you need a process name
that is unique, that means you need to copy wscript.exe (or cscript.exe) to
another name and use the copy to launch the main script (but not the child
scripts). This way you can e.g. use WMI from the child script to obtain the PID
to the parent.


Instead, a much easier solution is to use the VOLATILE environment for both the
writing and the *reading* (your second child script can't read it out of the
process environment, not unless the parent script is stopped and started again,
then anything previously added in the volatile environment will be seen in the
process environment).

In a way, you can say you use a registry write from child script 1 and then a
registry read from child script 2, but without using any registry methods (note
that the volatile environment is actually registry values, take a look at
registry key "HKEY_CURRENT_USER\Volatile Environment" after creating a volatile
environment variable. Another good thing with the VOLATILE environment is that
it is not persistent, it will be emptied when you log off.

For an example, put the three following vbscripts (Main, Script1 and Script2)
in the same folder and run the Main.vbs script.


'-------------- Main.vbs ----------------
Set Wshshell = CreateObject("WScript.Shell")

MsgBox "Main, will start script 1"
Wshshell.Run "wscript.exe Script1.vbs", 1, True

MsgBox "Back in main, will start script 2"
Wshshell.Run "wscript.exe Script2.vbs", 1, True
'--------------------8<----------------------


'-------------- Script1.vbs ----------------
Set Wshshell = CreateObject("WScript.Shell")

Set oVolatileEnv = Wshshell.Environment("VOLATILE")

Appvar1 = "123abcxyz"
oVolatileEnv("NameApp1") = Appvar1
'--------------------8<----------------------


'-------------- Script2.vbs ----------------
Set Wshshell = CreateObject("WScript.Shell")

Set oVolatileEnv = Wshshell.Environment("VOLATILE")
MsgBox "Content off NameApp1 in VOLATILE: " & oVOLATILEEnv("NameApp1")
'--------------------8<----------------------


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Re: Variables from one script to another by Houman

Houman
Mon Jan 19 21:17:54 CST 2004

Thanks very much, will try that tomorrow...
BTW, I'm still trying to reload or update the user environment stuff...

I'm still stuck at the same point....
Thanks !!!

--
--
Houman Yahyaei ( CCNA, MCSE Win 2000/NT 4.0, MCT )
IT Training and Consulting
www.formationhy.com
Houman@formationhy.com

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:400C6E8F.C3531499@hydro.com...
> Houman Yahyaei wrote:
>
> > Here is what I do :
> > I have a master script that calls other scripts...
> > 1st script called from master script, it declares and sets values for
some
> > variables ...
> > ex : Public appver1
> > appver1 = "V9_4_2"
> >
> > 2nd script called from master script would use the variables set in 1st
> > script to do execute actions with it...
> > ex : WshEnv("Var1") = appver1
> >
> > How can this be done ...
>
> Hi
>
> Ok, now I see what you mean. You want to update the process environment of
the
> parent process from a child script, so any new child processes (scripts)
from
> that parent process will see those changes (made by subscript 1).
>
> Updating the process environment of the parent process (from a child
process)
> with vbscript is not possible without using a 3rd party command line
utility
> that is able to set an environment variable in a foreign process (you will
need
> to feed it with the process ID (PID) of the foreign process). Setenv.exe
found
> at http://www.netexec.de/fs_lstools.html can do this, as well as
ConSet.exe
> found at http://home.pe.net/~fpw/freeware/ .
>
> This will end up pretty messy, because to get the PID, you need a process
name
> that is unique, that means you need to copy wscript.exe (or cscript.exe)
to
> another name and use the copy to launch the main script (but not the child
> scripts). This way you can e.g. use WMI from the child script to obtain
the PID
> to the parent.
>
>
> Instead, a much easier solution is to use the VOLATILE environment for
both the
> writing and the *reading* (your second child script can't read it out of
the
> process environment, not unless the parent script is stopped and started
again,
> then anything previously added in the volatile environment will be seen in
the
> process environment).
>
> In a way, you can say you use a registry write from child script 1 and
then a
> registry read from child script 2, but without using any registry methods
(note
> that the volatile environment is actually registry values, take a look at
> registry key "HKEY_CURRENT_USER\Volatile Environment" after creating a
volatile
> environment variable. Another good thing with the VOLATILE environment is
that
> it is not persistent, it will be emptied when you log off.
>
> For an example, put the three following vbscripts (Main, Script1 and
Script2)
> in the same folder and run the Main.vbs script.
>
>
> '-------------- Main.vbs ----------------
> Set Wshshell = CreateObject("WScript.Shell")
>
> MsgBox "Main, will start script 1"
> Wshshell.Run "wscript.exe Script1.vbs", 1, True
>
> MsgBox "Back in main, will start script 2"
> Wshshell.Run "wscript.exe Script2.vbs", 1, True
> '--------------------8<----------------------
>
>
> '-------------- Script1.vbs ----------------
> Set Wshshell = CreateObject("WScript.Shell")
>
> Set oVolatileEnv = Wshshell.Environment("VOLATILE")
>
> Appvar1 = "123abcxyz"
> oVolatileEnv("NameApp1") = Appvar1
> '--------------------8<----------------------
>
>
> '-------------- Script2.vbs ----------------
> Set Wshshell = CreateObject("WScript.Shell")
>
> Set oVolatileEnv = Wshshell.Environment("VOLATILE")
> MsgBox "Content off NameApp1 in VOLATILE: " & oVOLATILEEnv("NameApp1")
> '--------------------8<----------------------
>
>
> --
> torgeir
> Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of the 1328 page
> Scripting Guide: http://www.microsoft.com/technet/scriptcenter
>
>