Using C#, I have set the following environment variable using the following code:
RegistryKey key;
key = Registry.CurrentUser.CreateSubKey("Environment");
key.SetValue("MyDefaultBin", path);
The registry is updated in the right place, and the variable shows up under System > Advanced > Environment Variables, but I cannot access the path in my project files in Visual Studio as so: $(MyDefaultBin). Am I doing this incorrectly?
Newly configured environment variables are not added to existing processes. They are available to new processes that launch after the change.
Try restarting Visual Studio.
Also, if you are creating the variable for the “current user”, be sure you know who that user is. Sometimes code runs as a user different than the logged-in user, depending on what that code is doing.