Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > WindowsError: [Error 5] Access is denied With _winreg.enum

Reply
Thread Tools

WindowsError: [Error 5] Access is denied With _winreg.enum

 
 
black_13
Guest
Posts: n/a
 
      11-28-2007
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.
--------------------- script ----------------

import _winreg
import string

def reproduce_error():

for index in
xrange(_winreg.QueryInfoKey(_winreg.HKEY_LOCAL_MAC HINE)[0]):
#get names
name =
_winreg.EnumKey(_winreg.HKEY_LOCAL_MACHINE,index)
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)
print name

hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWA RE')
print hkey
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SAM')
print hkey

if __name__ == '__main__':
reproduce_error()
------------------- end script
-----------------------------------------
HARDWARE
SAM
Traceback (most recent call last):
File "winreg_error.py", line 19, in <module>
reproduce_error()
File "winreg_error.py", line 10, in reproduce_error
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)
WindowsError: [Error 5] Access is denied
 
Reply With Quote
 
 
 
 
Jerry Hill
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 2007 11:04 AM, black_13 <(E-Mail Removed)> 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_MAC HINE)[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
 
Reply With Quote
 
 
 
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      11-28-2007
On Nov 28, 10:04 am, black_13 <(E-Mail Removed)> 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.
> --------------------- script ----------------
>
> import _winreg
> import string
>
> def reproduce_error():
>
> for index in
> xrange(_winreg.QueryInfoKey(_winreg.HKEY_LOCAL_MAC HINE)[0]):
> #get names
> name =
> _winreg.EnumKey(_winreg.HKEY_LOCAL_MACHINE,index)
> hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)
> print name
>
> hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWA RE')
> print hkey
> hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SAM')
> print hkey
>
> if __name__ == '__main__':
> reproduce_error()
> ------------------- end script
> -----------------------------------------
> HARDWARE
> SAM
> Traceback (most recent call last):
> File "winreg_error.py", line 19, in <module>
> reproduce_error()
> File "winreg_error.py", line 10, in reproduce_error
> hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,name)
> WindowsError: [Error 5] Access is denied


If you move the "print name" line up one line, you'll notice that it's
choking on the Security key. Go to Start --> Run and type regedit. Go
to that key and right-click it and check its permissions.

On my PC the only user that has complete control is the SYSTEM. So
you'll probably just want to put an exception block in your function
that records the keys that you can't open and continues to run.

Mike
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very annoying error: Access to the path is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity Jay ASP .Net 2 08-20-2007 07:38 PM
403 Forbidden: You were denied access because: Access denied by access control list Southern Kiwi NZ Computing 6 03-19-2006 05:19 AM
Access Denied to access db with asp.net Ros@ ASP .Net 3 02-22-2006 04:51 PM
e-mail access denied by access control list Ram Ananthraman Computer Support 4 03-17-2005 09:22 PM
access denied by access control list Hung Computer Support 8 10-12-2003 05:27 PM



Advertisments