Discussion:
Urgent: Creating an Environment Variable (System Variable)?
(too old to reply)
Saurabh Bhatnagar
2005-02-07 14:01:05 UTC
Permalink
Hi People,

I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of System/Global
scope is system and not the current process), at the installation time. One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.

System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current process..... But
I need to create one for the System level scope.

I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts.... which I
don't want..

Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it can be
used by the specific application, with out restarting the system.

thanx in advance,
Saurabh
Phil Wilson
2005-02-08 17:14:23 UTC
Permalink
If this application is a Service, there's no way to cause it to refresh
without a system restart that I'm aware of.

The WM_SETTINGCHANGED message is what broadcasts these changes IIRC, but I
thought an MSI install broadcast one at the end of an install. When are you
starting the process?
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
Post by Saurabh Bhatnagar
Hi People,
I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of
System/Global
scope is system and not the current process), at the installation time. One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.
System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current process..... But
I need to create one for the System level scope.
I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts.... which I
don't want..
Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it can be
used by the specific application, with out restarting the system.
thanx in advance,
Saurabh
Saurabh
2005-02-09 14:39:07 UTC
Permalink
Hi Phil,

I finally got the solution .... :)
I am boradcasting 'WM_SETTINGCHANGE' message by invoking SendMessageTimeout
method (of user32.dll) by PInvoke. It is able to refresh the System Variables.

BTW I think that either the MSI Installer process is not broadcasting the
'WM_SETTINGCHANGE' message, or if at all it is, it's getting so before my
custom actions are closing. [I am using a custom action to create the System
variable].

What do you say?

thanks again,
Saurabh
Post by Phil Wilson
If this application is a Service, there's no way to cause it to refresh
without a system restart that I'm aware of.
The WM_SETTINGCHANGED message is what broadcasts these changes IIRC, but I
thought an MSI install broadcast one at the end of an install. When are you
starting the process?
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
Post by Saurabh Bhatnagar
Hi People,
I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of System/Global
scope is system and not the current process), at the installation time. One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.
System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current process..... But
I need to create one for the System level scope.
I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts.... which I
don't want..
Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it can be
used by the specific application, with out restarting the system.
thanx in advance,
Saurabh
Phil Wilson
2005-02-10 03:08:20 UTC
Permalink
If your custom actions are in Visual Studio setup projects, I think the
broadcast setting change is after them. I think it happens right at the end,
which is after your custom actions.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Post by Saurabh
Hi Phil,
I finally got the solution .... :)
I am boradcasting 'WM_SETTINGCHANGE' message by invoking
SendMessageTimeout
method (of user32.dll) by PInvoke. It is able to refresh the System Variables.
BTW I think that either the MSI Installer process is not broadcasting the
'WM_SETTINGCHANGE' message, or if at all it is, it's getting so before my
custom actions are closing. [I am using a custom action to create the System
variable].
What do you say?
thanks again,
Saurabh
Post by Phil Wilson
If this application is a Service, there's no way to cause it to refresh
without a system restart that I'm aware of.
The WM_SETTINGCHANGED message is what broadcasts these changes IIRC, but I
thought an MSI install broadcast one at the end of an install. When are you
starting the process?
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
Post by Saurabh Bhatnagar
Hi People,
I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of System/Global
scope is system and not the current process), at the installation time. One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.
System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current
process.....
But
I need to create one for the System level scope.
I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts.... which I
don't want..
Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it
can
be
used by the specific application, with out restarting the system.
thanx in advance,
Saurabh
Saurabh
2005-02-10 15:07:02 UTC
Permalink
Phil,
I am using s Custom action(a Console Application) to create the desired
System variable (I mean the registry entry in
'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
Manager\Environment' key), but after the custom actions are done and the
installation is over the Environment variable is not getting loaded ... but
now I am explicitly sending that message and its working fine....

Tell me if my approach is right one.....

thanz again,
Saurabh
Post by Phil Wilson
If your custom actions are in Visual Studio setup projects, I think the
broadcast setting change is after them. I think it happens right at the end,
which is after your custom actions.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Post by Saurabh
Hi Phil,
I finally got the solution .... :)
I am boradcasting 'WM_SETTINGCHANGE' message by invoking
SendMessageTimeout
method (of user32.dll) by PInvoke. It is able to refresh the System Variables.
BTW I think that either the MSI Installer process is not broadcasting the
'WM_SETTINGCHANGE' message, or if at all it is, it's getting so before my
custom actions are closing. [I am using a custom action to create the System
variable].
What do you say?
thanks again,
Saurabh
Post by Phil Wilson
If this application is a Service, there's no way to cause it to refresh
without a system restart that I'm aware of.
The WM_SETTINGCHANGED message is what broadcasts these changes IIRC, but I
thought an MSI install broadcast one at the end of an install. When are you
starting the process?
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
Post by Saurabh Bhatnagar
Hi People,
I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of System/Global
scope is system and not the current process), at the installation time. One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.
System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current
process.....
But
I need to create one for the System level scope.
I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts.... which I
don't want..
Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it
can
be
used by the specific application, with out restarting the system.
thanx in advance,
Saurabh
Phil Wilson
2005-02-12 20:25:55 UTC
Permalink
Well if you need the refreshed environment variables during the install
(because you're initiating a process during the install that needs them) I
don't think you have much choice, so do the broadcast in the install before
running your process. The Windows Installer documentation says that its
change broadcast doesn't happen until the end of the install, so it looks
like your solution is fine.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
Post by Saurabh
Phil,
I am using s Custom action(a Console Application) to create the desired
System variable (I mean the registry entry in
'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
Manager\Environment' key), but after the custom actions are done and the
installation is over the Environment variable is not getting loaded ... but
now I am explicitly sending that message and its working fine....
Tell me if my approach is right one.....
thanz again,
Saurabh
Post by Phil Wilson
If your custom actions are in Visual Studio setup projects, I think the
broadcast setting change is after them. I think it happens right at the end,
which is after your custom actions.
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Post by Saurabh
Hi Phil,
I finally got the solution .... :)
I am boradcasting 'WM_SETTINGCHANGE' message by invoking
SendMessageTimeout
method (of user32.dll) by PInvoke. It is able to refresh the System Variables.
BTW I think that either the MSI Installer process is not broadcasting the
'WM_SETTINGCHANGE' message, or if at all it is, it's getting so before my
custom actions are closing. [I am using a custom action to create the System
variable].
What do you say?
thanks again,
Saurabh
Post by Phil Wilson
If this application is a Service, there's no way to cause it to refresh
without a system restart that I'm aware of.
The WM_SETTINGCHANGED message is what broadcasts these changes IIRC,
but
I
thought an MSI install broadcast one at the end of an install. When
are
you
starting the process?
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Definitive Guide to Windows Installer
http://apress.com/book/bookDisplay.html?bID=280
in
Post by Saurabh Bhatnagar
Hi People,
I am installing a couple of .NET and non-.NET applications, using a Setup
and Deployment Project.
I need to create an Environment variable, (System Variable, of System/Global
scope is system and not the current process), at the installation
time.
One
of the .NET Application will require that Environment Variable to be passed
to it at the time of execution.
System.Environment class doesn't provide any way to Create a new Environment
variable, but the wayaround suggested by MS is to PInvoke
'SetEnvironmentVariable()' method of Kernel32.dll.
It creates an Environment variable but only for the current
process.....
But
I need to create one for the System level scope.
I tried creating a string value under the
HKeyLocalMachine\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment, which though creates the Environment variable but
doesn't loads it into the memory, untill the system restarts....
which
I
don't want..
Can anyone tell me a way to somehow Inject this newly created Enviromnet
Variable in memory... or an Win32 API which can be used to create and
simultaneously load the created system variable in memory, so that it
can
be
used by the specific application, with out restarting the system.
thanx in advance,
Saurabh
Loading...