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

Barbara Streisand
Release: 2024-11-16 00:37:03
Original
470 people have browsed it

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"
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template