What is the correct address in the Windows 10 Registry from which to get and set the PATH variable?
当我运行下面的Python程序时,以下三个选项都不起作用:
from winreg import *
#The following line (uncommented) gives a list of things including Environment
keyVal = r"SYSTEM\CurrentControlSet\Control\Session Manager"
#The following line (uncommendted) gives an empty list of results (nothing)
#keyVal = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
#The following line (uncommented) gives an error message as follows: "FileNotFoundError: [WinError 2] The system cannot find the file specified"
#keyVal = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
aKey = OpenKey(HKEY_LOCAL_MACHINE, keyVal, 0, KEY_ALL_ACCESS)
try:
i = 0
while True:
asubkey = EnumKey(aKey, i)
print(asubkey)
i += 1
except WindowsError:
pass
调用上面的Python代码时,Windows CMD正在以管理员身份运行。我以管理员身份运行Windows CMD,希望在运行上述脚本访问注册表项时避免权限问题
Note: When I type
regedit
into the Windows Start Menu, and I drill down toComputer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
, I am able to see a properly-populatedPath
variable. Even though the error shown above is given when I try to access this programmatically as an administrator.
2nd Note: When I try the code at this link per @SimonCrane 's suggestion, and call the function with
open_env_registry_key('system')
, the result is an error whenSYS_ENV_SUBPATH = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
, or no results at all when usingSYS_ENV_SUBPATH = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
orSYS_ENV_SUBPATH = r"SYSTEM\CurrentControlSet\Control\Session Manager"
,
目前没有回答
相关问题 更多 >
编程相关推荐