使用 Python 设置 Windows XP 注册表项权限 [英] Setting Windows XP registry key permissions using Python

查看:49
本文介绍了使用 Python 设置 Windows XP 注册表项权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个客户管理了他们注册表的一部分.由于某种原因,HKEY_CLASSES_ROOT 下的一堆子键没有设置权限.所以我正在检查键并手动设置键:

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. 将管理员添加为组
  2. 将管理员设置为所有者

可能需要设置数以千计的这些,每个键需要 10 到 12 个步骤.所以我想通过 Python 自动化这个过程.有没有一个模块可以同时完成这两个任务?

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?

谢谢!

推荐答案

经过几乎一整天的研究,我使用 Windows 注册表和权限的解决方案是使用 SetACL.您可以使用 COM 对象,或使用二进制文件和子流程模块.这是我在代码中用于修改混合环境中权限的片段(我有大约 50 台 Windows 机器,32 位和 64 位,Windows 7 和 Windows XP 专业版......):

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()

所以,它不是真正的纯 Python,但它可以工作.

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

这篇关于使用 Python 设置 Windows XP 注册表项权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆