Home  >  Article  >  Backend Development  >  How to Set Environment Variables for Users with Restricted Privileges in Windows?

How to Set Environment Variables for Users with Restricted Privileges in Windows?

Barbara Streisand
Barbara StreisandOriginal
2024-11-16 00:37:03474browse

How to Set Environment Variables for Users with Restricted Privileges in Windows?

Setting Environment Variables in Windows

User environment variables in Windows provide a convenient way to store configuration values for applications. This article explores how to set these variables with restricted user privileges.

Issue:

Unable to read user-created environment variables (ADDR and TOKEN) using os.Getenv().

Cause:

The set command creates temporary, per-session environment variables, while setx creates permanent, system-wide variables. User privileges are insufficient to create system variables, and os.Getenv() reads only system variables.

Solution:

To set user environment variables, use the setx command.

Example:

To set the ADDR and TOKEN variables using setx:

cmd> setx ADDR "127.0.0.1"
cmd> setx TOKEN "ABCD1234"

Once set, the variables will be accessible to future shell sessions and applications. Note that existing shell sessions will need to be closed and reopened for the changes to take effect.

The above is the detailed content of How to Set Environment Variables for Users with Restricted Privileges in Windows?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn