I need to setup an environment variable from a C# program so batch files that run later can use this newly created variable. I have tried using:

Environment.SetEnvironmentVariable("USRNAM", "My Name", 
                                    EnvironmentVariableTarget.Process);

After this statement I have a breakpoint setup and when it gets to this breakpoint, I go to a Command Prompt, issue the following command:

C:\Users\Lenovo>SET USRNAM

I get:

Environment variable USRNAM not defined.

How can I set an Environment variable that persists after the C# program execution has completed?

Suggestions are very much appreciated.

c#
Edit
Report