# Cannot create an environment variable in the registry

I have a personalized installer activity that updates the PATH environment, and also develops an added environment variable. Adding a directory site to the existing course variable is functioning penalty, but also for some factor my efforts to create a new environment variable have actually been not successful. The code I am making use of is:

        using (RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true))
{
reg.SetValue("MYVAR", "SomeVal", RegistryValueKind.ExpandString);
}


Edit: The OS is 32 - little bit XP, and also regarding I can inform it is falling short calmly.

0
2022-06-07 14:30:18
Source Share

It ends up there was an additional trouble that was protecting against the code in my inquiry from being called. Nonetheless, I was making use of the Win32 setting up due to the fact that the instance code I was adhering to was created prior to the Environment setting up appeared. So Thanks Peter for mentioning the Environment API.

0
2022-06-07 18:57:31
Source

What OS is this? Is it on a 64 - little bit system? What is the nature of the failing: quiet or is an exemption tossed?

You can attempt running ProcessMonitor and also seeing if it sees the effort to set the value.

1
2022-06-07 15:05:34
Source

Is there any kind of factor that you need to do it via the registry?

Otherwise, you can make use of Environment.SetEnvironmentVariable() since.NET 2.0. It permits you to set on an equipment, procedure or customer basis.

1
2022-06-07 15:05:26
Source