I am trying to set path environment variable for MySql
.
I don't get an error, but my code doesn't work.
Code:
First:
string pathvar = @";C:\Program Files\MySQL\MySQL Server 5.1\bin\\";
System.Environment.SetEnvironmentVariable("PATH", pathvar);
Second:
string pathvar = System.Environment.GetEnvironmentVariable("PATH");
System.Environment.SetEnvironmentVariable("PATH", pathvar + @";C:\Program Files\MySQL\MySQL Server 5.1\bin\\");
Thank you for your help...
Set PATH and other environment variables in Windows 10 1 Windows XP - Right-click My Computer, and then click Properties → Advanced → Environment variables → Choose New, Edit or... 2 Windows 7 - Click on Start → Computer → Properties → Advanced System Settings → Environment variables → Choose New, Edit... More ...
Note: You can edit other environment variables by highlighting the variable in the "System variables" section and clicking Edit. If you need to create a new environment variable, click New and enter the Variable name and Variable value. To view and set the path in the Windows command line, use the path command.
Setting the path and variables in Windows Vista and Windows 7. From the Desktop, right-click the Computer icon and select Properties. Click the Advanced System Settings link in the left column. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
Add directory to system path environment variable: Open administrator command prompt. Run the below command. pathman /as directoryPath. Remove path from system path environment variable: Run the below command from elevated command prompt. pathman /rs directoryPath.
You are associating the environment variable with your program, but instead you want to associate it with your local machine in order to make it available to every program. Look at the overload that takes an EnvironmentVariableTarget
.
var name = "PATH";
var scope = EnvironmentVariableTarget.Machine; // or User
var oldValue = Environment.GetEnvironmentVariable(name, scope);
var newValue = oldValue + @";C:\Program Files\MySQL\MySQL Server 5.1\bin\\";
Environment.SetEnvironmentVariable(name, newValue, scope);
Calling SetEnvironmentVariable has no effect on the system environment variables. Check this answer here:
https://stackoverflow.com/a/19705691/1057667
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With