WindowsError: [Error 5] Access is denied With _winreg.enum
Jerry Hill
malaclypse2 at gmail.com
Wed Nov 28 11:28:53 EST 2007
On Nov 28, 2007 11:04 AM, black_13 <jjosburn at gmail.com> wrote:
> I have included a small script the reproduces the error I am having in
> larger script. The line 'hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)'
> seems to be causing the error but im not sure why.
...
> WindowsError: [Error 5] Access is denied
Your user does not have permission to open the registry key you
requested. On my local machine, HKEY_LOCAL_MACHINE/SECURITY is only
accessible by the SYSTEM account. Even Administrative users do not
have Read rights to that key by default.
If you want to skip keys you don't have permission to access, you
could do something like this:
import _winreg
for index in xrange(_winreg.QueryInfoKey(_winreg.HKEY_LOCAL_MACHINE)[0]):
try:
name = _winreg.EnumKey(_winreg.HKEY_LOCAL_MACHINE,index)
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)
except WindowsError:
print "Could not access registry key", name
else:
print name, hkey
--
Jerry
More information about the Python-list
mailing list