在 Python 中从注册表中读取 HKEY CURRENT USER,指定用户

编程入门 行业动态 更新时间:2024-10-10 01:21:21
本文介绍了在 Python 中从注册表中读取 HKEY CURRENT USER,指定用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我在几个不同的用户帐户下运行子进程.我需要能够读取这些子进程写入注册表的一些信息.每个人都在写 HKEY_CURRENT_USER,我知道他们正在运行的用户帐户名.

In my application I run subprocesses under several different user accounts. I need to be able to read some of the information written to the registry by these subprocesses. Each one is writing to HKEY_CURRENT_USER, and I know the user account name that they are running under.

在 Python 中,如何从 HKEY_CURRENT_USER 读取特定用户的值?我假设我需要以某种方式加载用户名下的注册表值,然后从那里读取它们,但是如何?

In Python, how can I read values from HKEY_CURRENT_USER for a specific user? I assume I need to somehow load the registry values under the user's name, and then read them from there, but how?

为了确保清楚,我的 Python 程序以管理员身份运行,我有帐户user1"、user2"和user3",每个帐户在自己的 HKEY_CURRENT_USER 中都有信息.作为管理员,我如何读取 user1 的 HKEY_CURRENT_USER 数据?

edit: Just to make sure it's clear, my Python program is running as Administrator, and I have accounts "user1", "user2", and "user3", which each have information in their own HKEY_CURRENT_USER. As Administrator, how do I read user1's HKEY_CURRENT_USER data?

推荐答案

根据 MSDN,HKEY_CURRENT_USER 是指向当前用户的HKEY_USERS/SID的指针.您可以使用 pywin32 来查找帐户名称的 SID.一旦你有了这个,你可以使用 open 并使用带有 _winreg 模块的注册表项.

According to MSDN, HKEY_CURRENT_USER is a pointer to HKEY_USERS/SID of the current user. You can use pywin32 to look up the SID for an account name. Once you have this, you can use open and use the registry key with the _winreg module.

import win32security import _winreg as winreg sid = win32security.LookupAccountName(None, user_name)[0] sidstr = win32security.ConvertSidToStringSid(sid) key = winreg.OpenKey(winreg.HKEY_USERS, sidstr) # do something with the key

更多推荐

在 Python 中从注册表中读取 HKEY CURRENT USER,指定用户

本文发布于:2023-10-31 10:13:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注册表   用户   Python   HKEY   USER

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!