472,958 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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

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
Nov 28 '07 #1
2 12700
On Nov 28, 2007 11:04 AM, black_13 <jj******@gmail.comwrote:
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
Nov 28 '07 #2
On Nov 28, 10:04 am, black_13 <jjosb...@gmail.comwrote:
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
Nov 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce A. Julseth | last post by:
What am I doing wrong? Do I have something set up (config file, et.al) wrong? The following is the senerio: Login as: mysql -u root Run cmd: grant all on * to fred identified by 'julebj';...
3
by: John Sellers | last post by:
newbee question...I haven't worked on Python since Python 1.5.2 cygwin setup installs Python 2.3.2-1 on Windows XP however: $ python Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
1
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System...
22
by: James Kupernik | last post by:
Hello everyone! I'm hoping someone can shed some light on my ever daunting mysql/php problem. I'm currently trying to get a new server up and running using apache/php/mysql. Everything runs...
2
by: future_retro | last post by:
In the following script I can't get the reg key to unload. Anyone got any ideas? I can load and save the key without any problems. I can unload the key from regedit and have checked security on...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
25
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program...
0
by: trayres | last post by:
Hi all! I'm trying to use ctypes to access a function in a DLL. Here is the function prototype: extern "C" void__stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.