Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to add to the PATH environment variable. This can be done in either C# or command line.

 

I know in the cl I can do: SET PATH=%PATH%;c:\mypath , however this seems to only be a temorary thing. When I look at environment variables from My Computer->Properties, the path does not show. It only shows when I echo the PATH in the command line. When I reboot the computer, it is gone.

 

So, does anyone know how to add to the PATH environment variable and make it stay there?

Posted
When you were setting the path variable via the command line you were setting it only for that instance of the command prompt. As a matter of fact, the path variable that you set won't appear in another instance of a command prompt either -- it is only for the instance you set it in. When you set an environment variable via "My Computer" or the registry, it will be permanent. If you just need to add something to your path and it is not application specific, "My Computer" is the easiest way to go.
Posted

I did need to add a system path. The purpose of writing this app is to automate the process of configuring 20 different things into a simple button click. Going to my computer would defeat the purpose.

 

I found which registry key the path was in and here is the code that will modify it.

 

private void setEnvPath(string strNewPath)
{
 RegistryKey key = Registry.LocalMachine;
 key = key.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",true);

 key.SetValue("Path", strNewPath );
 key.Close();
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...