How to read a user environment variable in C#?

后端 未结 4 2033
北荒
北荒 2021-02-12 12:56

How can I read a user specific environment variable? I know how to get a system wide one, like

Environment.GetEnvironmentVariable(\"SOMETHING\");
4条回答
  •  执笔经年
    2021-02-12 13:47

    Use the other overload of the Environment.GetEnvironmentVariable Method that lets you specify the EnvironmentVariableTarget.

    Environment.GetEnvironmentVariable(variable, target);
    

    target can be:
    EnvironmentVariableTarget.Process,
    EnvironmentVariableTarget.User,
    EnvironmentVariableTarget.Machine.

提交回复
热议问题