Hi all,

i have the following problem
sorry my english is not that great.

I have 1 vbscript in with 2 things happen

1: install an MSI if not installed
2: if MSI is installed execute the advertised shortcut.

the script works great but we have one issue
If the MSI (we take ORACLE for example) set or expands a windows
systems variable like the "Path=%Path%;C:\Oralce" the seconde action
of the script doen't expands environment variables like the path en
ORACLE gives a error becourse the path is nog found.

This is becourse the vbscript doen't expands the new installed windows
variable.
my question is how can I expand reload the windows environment
variables in a running VBSCRIPT?

i have many workarrounds like putting the environments in a
logonscript and solutions like that but I want 1 vbscript.

can anybody help me i am not that great with vbscipt.

greatings
Roger

RE: Environment issue's Please help by RemS

RemS
Sun May 20 04:38:00 CDT 2007



"Rogier" wrote:

> Hi all,
>
> i have the following problem
> sorry my english is not that great.
>
> I have 1 vbscript in with 2 things happen
>
> 1: install an MSI if not installed
> 2: if MSI is installed execute the advertised shortcut.
>
> the script works great but we have one issue
> If the MSI (we take ORACLE for example) set or expands a windows
> systems variable like the "Path=%Path%;C:\Oralce" the seconde action
> of the script doen't expands environment variables like the path en
> ORACLE gives a error becourse the path is nog found.
>
> This is becourse the vbscript doen't expands the new installed windows
> variable.
> my question is how can I expand reload the windows environment
> variables in a running VBSCRIPT?
>
> i have many workarrounds like putting the environments in a
> logonscript and solutions like that but I want 1 vbscript.
>
> can anybody help me i am not that great with vbscipt.
>
> greatings
> Roger
>
>


Hoi Rogier,

Normaly with
WSHShell.Environment.item("nwVariableName") = ....
you can set the System variable during a session.
It will: 1- wright to registry
2- udate the session environment
3- delete from registry (!)
Now you can use the variable.

But to make it permanent you have to write it again to the registry after 10
! seconds or something:
"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\"
And make sure this part of the script only run once.

note:
When you want to write it afterwards to registry to make it persistent, you
have to *exand the current variable* first and add the new value to the
string, then write the *complete* string to the registry.



note also that Only members of the local administrators group can set system
environment.
"Any user can add, modify, or remove a user environment variable. However,
only an administrator or systemaccount can add, modify, or remove a system
environment variable"
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/environment_variables.mspx?mfr=true
-!- So you cannot use the method above with a user logon script -!-.

The best way to add an entry to the %path% system variable,
is to create "path" ALSO as user variable,
with the string value: %path%;nwVariableName
(it reads the systemvalue to)

To add and to ACTIVATE new environment variables you need a thirdparty tool
"SetEnv.exe"
like this:

Set objShell = CreateObject("WScript.Shell")
strSettings = "...."
objShell.Run "path\SetEnv.exe " & strSettings, 0, True
Set objShell = Nothing

On the internet you can find TWO versions of that tool:
1. SetEnv.exe (lighter than the other one)
- http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849
- http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849
OR:
2. SETENV.EXE (this one has more functionality)
- http://www.jsifaq.com/sf/tips/tip.aspx?id=4928
- http://www.windowsnetworking.com/nt/atips/atips343.shtml


\Rems

Re: Environment issue's Please help by Rogier

Rogier
Mon May 21 03:19:01 CDT 2007

Yeah this is the wa to do it from a script i know this.

Problem lies in the fact that the MSI installs the environment not the
script in with i first run a MSI and then the App installed with de
MSI.

If the MSI contains a environment variable it is set bij de MSI and it
is active to use but mij parent VBS script is still running with the
old environments.

Thanks for youre comment but this is not the solution to my problem.
I need te find a way to update de environments from my parent VBS
script.

anybody?


Re: Environment issue's Please help by RemS

RemS
Mon May 21 05:02:01 CDT 2007

"Rogier" wrote:

> Yeah this is the wa to do it from a script i know this.
>
> Problem lies in the fact that the MSI installs the environment not the
> script in with i first run a MSI and then the App installed with de
> MSI.
>
> If the MSI contains a environment variable it is set bij de MSI and it
> is active to use but mij parent VBS script is still running with the
> old environments.
>
> Thanks for youre comment but this is not the solution to my problem.
> I need te find a way to update de environments from my parent VBS
> script.
>
> anybody?
>

The tool SetEnv.exe WILL UPDATEs all the variables to the New Environment
(see the links in my previous reply). That is what makes the tool special.

There can *only be one* environment current per computer/user, So it is not
possible the parent/initiating VBS script is still running with the old
environments, unless the initiating script reads the "previous" environment
variable only once and set it as a parameter with its own name, and the
script continue using the parameter name instead of keepon re-reading the
environment variable? OR Else something goes wrong trying to set the new
environment and was not succesful.

To help you with this, we have to take a look at both scripts.


\RemS

Re: Environment issue's Please help by Rogier

Rogier
Wed May 23 02:50:11 CDT 2007

On May 21, 12:02 pm, \RemS <R...@discussions.microsoft.com> wrote:
> "Rogier" wrote:
> > Yeah this is the wa to do it from a script i know this.
>
> > Problem lies in the fact that the MSI installs the environment not the
> > script in with i first run a MSI and then the App installed with de
> > MSI.
>
> > If the MSI contains a environment variable it is set bij de MSI and it
> > is active to use but mij parent VBS script is still running with the
> > old environments.
>
> > Thanks for youre comment but this is not the solution to my problem.
> > I need te find a way to update de environments from my parent VBS
> > script.
>
> > anybody?
>
> The tool SetEnv.exe WILL UPDATEs all the variables to the New Environment
> (see the links in my previous reply). That is what makes the tool special.
>
> There can *only be one* environment current per computer/user, So it is not
> possible the parent/initiating VBS script is still running with the old
> environments, unless the initiating script reads the "previous" environment
> variable only once and set it as a parameter with its own name, and the
> script continue using the parameter name instead of keepon re-reading the
> environment variable? OR Else something goes wrong trying to set the new
> environment and was not succesful.
>
> To help you with this, we have to take a look at both scripts.
>
> \RemS- Hide quoted text -
>
> - Show quoted text -

Again I know how to set it with scripting but can use this tool,
nut if you read my post i want to set it with MSI so not from a
script.

the MSIEXEC does not return the new variables so to the parent.


Re: Environment issue's Please help by RemS

RemS
Thu May 24 18:52:01 CDT 2007

"Rogier" wrote:
> On May 21, 12:02 pm, \RemS <R...@discussions.microsoft.com> wrote:
> > "Rogier" wrote:
> > > Yeah this is the wa to do it from a script i know this.
> >
> > > Problem lies in the fact that the MSI installs the environment not the
> > > script in with i first run a MSI and then the App installed with de
> > > MSI.
> >
> > > If the MSI contains a environment variable it is set bij de MSI and it
> > > is active to use but mij parent VBS script is still running with the
> > > old environments.
> >
> > > Thanks for youre comment but this is not the solution to my problem.
> > > I need te find a way to update de environments from my parent VBS
> > > script.
> >
> > > anybody?
> >
> > The tool SetEnv.exe WILL UPDATEs all the variables to the New Environment
> > (see the links in my previous reply). That is what makes the tool special.
> >
> > There can *only be one* environment current per computer/user, So it is not
> > possible the parent/initiating VBS script is still running with the old
> > environments, unless the initiating script reads the "previous" environment
> > variable only once and set it as a parameter with its own name, and the
> > script continue using the parameter name instead of keepon re-reading the
> > environment variable? OR Else something goes wrong trying to set the new
> > environment and was not succesful.
> >
> > To help you with this, we have to take a look at both scripts.
> >
> > \RemS- Hide quoted text -
> >
> > - Show quoted text -
>
> Again I know how to set it with scripting but can use this tool,
> nut if you read my post i want to set it with MSI so not from a
> script.
>
> the MSIEXEC does not return the new variables so to the parent.
>

Rogier, I guess you misunderstood my replies, they weren't about "I know
what you don't know".

It more likely the other way around in some points. You could have taken the
opertunity to tell us what you *actualy have tried* so far. And, it could
also be usefull if you mensioned what environment level exactly is configured
during the MSIEXEC install User | Machine | default user | Volatile env (->
depends in which registrykey the value is added). Or, maybe, the environment
is enhanced by a process everytime?.
And, how is the script trying to expand the value now, and how exactly is
that used further in the script.

But, apart from that, you are correct;
- the MSI package installation probably already takes care for updating the
environment.
- but it only cannot RETURN the new variables to the parent. That vbs uses
and
passing the originating variables that was current on the time the script
was
executed.

~ ~ ~
You are lucky if the environment variable value is set or added in one of
the two keys below;
HKLM\System\CurrentControlSet\Control\
Sessionmanager\Environment
OR
HKEY_USERS\<user>\Environment

In that case you can use the WMIService to query the Environment:
(even w/out the use of SetEnv.exe first)

'---------------------------

enVariable1 = "path"
strComputer = "."

Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")

Set colVar = objWMIService.ExecQuery( _
"Select * from Win32_Environment where Name = '"& enVariable1 &"'")
For Each objVar in colVar
varValue1 = objVar.VariableValue
' exit For
Next

Set WshShell = WScript.CreateObject("WScript.Shell") '<--- optional
wscript.echo WshShell.ExpandEnvironmentStrings(varValue1)

'---------------------------

If not in these registrykeys, then i'm afraid there is no solution :(

I hope the Win32_Environment works for you.

grtz.
~ ~ ~


"For others who reads this topic and are intrested in SetEnv.exe ...."
The tool SetEnv.exe is able to force a *reload of the environment* w/out
re-logon or the need for a reboot.
It can be executed after changes were made to one of the 4 environment keys
in the registry.
The tool can runned from a vbscript like this for example:

enVariable = "PATH"
Set WshShell = WScript.CreateObject("WScript.Shell")
strProg = "\\unc-or-localpath\SetEnv.exe"
WshShell.Run chr(34) & strProg & chr(34) & " $fake$ -delete",0 , TRUE

'(for that you have to use this version of SetEnv.exe !:
' http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849
' btw this the one with more functionality, I mixed both up in my first
reply)

This script will refresh the environment for every new script and every
application on this computer runned afterwards. But it canNOT change the
environment for the script itself and it will even passing that old
environment to the scripts that were, and to scripts that are going to be
executed by this script, and even the scripts that were executed by the
scripts or batches that were executed from within the initiation script are
still in the 'old' environment !!!

\RemS

Re: Environment issue's Please help by RemS

RemS
Fri May 25 04:28:01 CDT 2007

> If not in one of these 2 registrykeys, then i'm afraid there is no solution
:(

Exept, of course, if it is only for the script you don't have use the
%environment% but instead you could getting the updated stringvalue direct
from one of the 4 registrykeys.
http://www.serverwatch.com/tutorials/print.php/1476861

You can add this method as a function to the script

\Rems