Urgent: Creating an Environment Variable (System Variable)?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
I've run into this problem myself with some scripts. You don't need a full
restart here, restarting explorer should be sufficient. Another option is
to broadcast a message that you updated an env var. Applications don't have
to respond to this but many do.
 
Back
Top