473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 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 12791
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.