Setting Environment Variables in Windows with User Privileges
Setting environment variables is an essential aspect of configuring system settings and providing access to necessary information. This article discusses how to set environment variables in Windows with user privileges only, given that you may not have the authorization to modify system variables.
The code snippet below attempts to read environment variables using the os.Getenv() function:
var ( Address = os.Getenv("ADDR") Token = os.Getenv("TOKEN") )
Windows provides two strategies for modifying environment variables:
To set environment variables with user privileges, use the following approaches:
Temporary Setting (Set)
set ADDR=127.0.0.1
This command will temporarily set the "ADDR" environment variable to "127.0.0.1" within the current shell.
Permanent Setting (Setx)
setx ADDR "127.0.0.1"
This command will add the "ADDR" environment variable to the system-wide registry with the value "127.0.0.1" and it will be available in all future shells.
The above is the detailed content of How to Set Environment Variables in Windows with User Privileges?. For more information, please follow other related articles on the PHP Chinese website!