How can I read a user specific environment variable? I know how to get a system wide one, like
Environment.GetEnvironmentVariable("SOMETHING");
Thanks in advance!
An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.
To access the value of an environment variable from a COBOL program, call the getenv() function. To set environment variables for z/OS UNIX COBOL programs from a shell, use the export or set command. To set environment variables from within the program, call POSIX functions setenv() or putenv().
Select Start > All Programs > Accessories > Command Prompt. In the command window that opens, enter set. A list of all the environment variables that are set is displayed in the command window.
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
.
It's the same method, just set the second parameter to be User
as:
System.Environment.GetEnvironmentVariable("varName", EnvironmentVariableTarget.User);
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