6

Is there way to determine which environment variables returned by os.environ belongs to current user and which one - to all users? I do not want to change it, only get.

UPD: I am using Microsoft Windows 7.

12
  • 1
    What operating system are you running? Commented Jun 14, 2015 at 23:17
  • 1
    It's os.environ not os.environ() Commented Jun 14, 2015 at 23:27
  • @maxymoo No. Commented Jun 15, 2015 at 9:11
  • What do you mean by "belongs"? How does an environment variable belong to a user or to all users? Commented Jun 15, 2015 at 9:13
  • @Tichodroma there is such thing on Windows Commented Jun 15, 2015 at 9:16

2 Answers 2

3

I don't think you can figure it out using standard Python means like os.environ. The only way to get user and system variables on Windows is to use registry, you can find more here:

HKEY_CURRENT_USER\Environment

System Variables

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

User variables

You need to access registry with Python to get them.

Sign up to request clarification or add additional context in comments.

Comments

-2

you can get all the variables by

import os print(os.environ)

this will return you the dictionary type of output with keys as enviornment variables and values as the values of the enviornment variables.

to get the current username:

print(os.environ['USERNAME'])

Look for yourself what you want in the dictionary.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.