GetEnvironmentVariable() and SetEnvironmentVariable() for PATH Variable

后端 未结 6 1648

I want to extend the current PATH variable with a C# program. Here I have several problems:

  1. Using GetEnvironmentVariable(\"PATH\", EnvironmentVariable

6条回答
  •  执笔经年
    2020-12-11 16:03

    You could go through the registry...

    string keyName = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
    //get raw PATH environment variable
    string path = (string)Registry.GetValue(keyName, "Path", "");
    
    //... Make some changes
    
    //update raw PATH environment variable
    Registry.SetValue(keyName, "Path", path);
    

提交回复
热议问题