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.
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.
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.
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.