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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • black_13

    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_L OCAL_MACHINE,na me)'
    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(_w inreg.HKEY_LOCA L_MACHINE)[0]):
    #get names
    name =
    _winreg.EnumKey (_winreg.HKEY_L OCAL_MACHINE,in dex)
    hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,na me)
    print name

    hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,'S OFTWARE')
    print hkey
    hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,'S AM')
    print hkey

    if __name__ == '__main__':
    reproduce_error ()
    ------------------- end script
    -----------------------------------------
    HARDWARE
    SAM
    Traceback (most recent call last):
    File "winreg_error.p y", line 19, in <module>
    reproduce_error ()
    File "winreg_error.p y", line 10, in reproduce_error
    hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,na me)
    WindowsError: [Error 5] Access is denied
  • Jerry Hill

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

    On Nov 28, 2007 11:04 AM, black_13 <jjosburn@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_L OCAL_MACHINE,na me)'
    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_MACH INE/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(_w inreg.HKEY_LOCA L_MACHINE)[0]):
    try:
    name = _winreg.EnumKey (_winreg.HKEY_L OCAL_MACHINE,in dex)
    hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,na me)
    except WindowsError:
    print "Could not access registry key", name
    else:
    print name, hkey

    --
    Jerry

    Comment

    • kyosohma@gmail.com

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

      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_L OCAL_MACHINE,na me)'
      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(_w inreg.HKEY_LOCA L_MACHINE)[0]):
      #get names
      name =
      _winreg.EnumKey (_winreg.HKEY_L OCAL_MACHINE,in dex)
      hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,na me)
      print name
      >
      hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,'S OFTWARE')
      print hkey
      hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,'S AM')
      print hkey
      >
      if __name__ == '__main__':
      reproduce_error ()
      ------------------- end script
      -----------------------------------------
      HARDWARE
      SAM
      Traceback (most recent call last):
      File "winreg_error.p y", line 19, in <module>
      reproduce_error ()
      File "winreg_error.p y", line 10, in reproduce_error
      hkey = _winreg.OpenKey (_winreg.HKEY_L OCAL_MACHINE,na me)
      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

      Comment

      Working...