sde Posted November 16, 2005 Posted November 16, 2005 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? Quote codenewbie
Cags Posted November 16, 2005 Posted November 16, 2005 I'm not sure exactly what your trying to achieve but the following article may help, it discusses application specific paths. Its in the c++ section, but I can't see that mattering. http://www.codeguru.com/Cpp/W-P/dll/article.php/c99 Quote Anybody looking for a graduate programmer (Midlands, England)?
sde Posted November 16, 2005 Author Posted November 16, 2005 ah yes, that makes sense. a registry setting. Thanks!! Quote codenewbie
mskeel Posted November 16, 2005 Posted November 16, 2005 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. Quote
sde Posted November 17, 2005 Author Posted November 17, 2005 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(); } Quote codenewbie
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.