0

A client of mine hosed part of their registry. For some reason, a bunch of sub keys under the HKEY_CLASSES_ROOT have no permissions set. So I am going through the keys and manually setting keys as such:

  1. Add Administrators as a group
  2. Set Administrators as the Owner

There are potentially thousands of these that need to be set and it's a 10-12 step process to do for each key. So I want to automate the process via Python. Is there a module that can accomplish both of these?

Thanks!

2
  • 2
    take a look at docs.python.org/library/_winreg.html Commented Mar 17, 2012 at 21:02
  • @JoranBeasley, the _winreg module is poorly documented. And so is in General the situtation regarding Windows Registry. The people in Redmond created a beast they don't even fully understand... Commented May 16, 2012 at 11:44

1 Answer 1

1

After almost a whole day research my solution to working with windows registry and permissions is to use SetACL. You could use a COM object, or use the binary file and the subprocess module. Here is a snippet from what I used in my code to modify the permissions in a mixed environment (I have ~50 Windows machines with 32bit and 64bit, with Windows 7 and Windows XP pro ...):

from subprocess import Popen, PIPE

def Is64Windows():
    '''check if win64 bit'''
    return 'PROGRAMFILES(X86)' in os.environ

def ModifyPermissions():
    """do the actual key permission change using SetACL"""
    permissionCommand = r'SetACL.exe -on "HKLM\Software\MPICH\SMPD"'\
    +' -ot reg -actn ace -ace "n:Users;p:full"'
    permissionsOut = Popen(permissionCommand, stdout = PIPE, stderr = PIPE)
    pout, perr = permissionsOut.communicate()
    if pout:
        print pout
        sys.exit(0)
    elif perr:
        print perr
        sys.exit(1)

def main():
    ... some code snipped ...

    os.chdir('SetACL')
    if Is64Windows():
        os.chdir('x64')
        ModifyPermissions()
    else:
        os.chdir('x86')
        ModifyPermissions()

So, it's not really pure Python, but it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.