GetEnvironmentVariable() and SetEnvironmentVariable() for PATH Variable

后端 未结 6 1653

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 15:58

    You can use WMI to retrieve the raw values (not sure about updating them though):

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Environment WHERE Name = 'PATH'");
    foreach (ManagementBaseObject managementBaseObject in searcher.Get())
         Console.WriteLine(managementBaseObject["VariableValue"]);
    

    Check WMI Reference on MSDN

提交回复
热议问题