如何刷新注册表值

发布于 2024-10-05 04:39:18 字数 143 浏览 0 评论 0原文

我正在卸载一些应用程序并从注册表中读取软件安装枚举值。

问题是卸载后,除非屏幕或注册表未刷新,否则它不会更改注册表值。刷新后我才得到正确的值。

有人可以帮我刷新 python 代码中的 regedit 吗?

问候, 乌彭德拉

I am uninstalling some application and reading the software installation enumeration value from registry.

The problem is after uninstallation it is not changing the registry value untill unless the screen or regedit is not refreshed. after refreshing only i am getting the correct value.

Could some one help me out to refresh the regedit in python codes.

Regards,
upendra

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清醇 2024-10-12 04:39:18

我认为“刷新”“屏幕”是指重新启动计算机吗?无论如何,您可以确定您修改的任何注册表项都将在系统重新启动后正确更新。注册表是通过延迟刷新和编写器线程进行更新的,所以我的猜测是您所做的更改不会立即刷新回注册表,但是您的问题没有提供有关如何修改这些注册表值的足够信息让我能够提出替代解决方案。

也许更重要的是,你想在这里做什么?您是否正在尝试让卸载程序验证您的应用程序是否已卸载?为什么这是必要的?我觉得必须有一种比期望提交注册表编辑然后立即读回更好的方法。

I assume that by "refreshing" the "screen," you mean restarting the computer? Regardless, you can be sure that whatever registry keys you've modified will be correctly updated after the system is restarted. The registry is updated with lazy flush and writer threads, so my guess is that the changes you're making aren't flushed back to the registry immediately, but your question doesn't provide enough information about how you're modifying these registry values for me to be able to propose an alternative solution.

Perhaps more importantly, what are you trying to do here? Are you trying to get your uninstaller to verify that your application has been uninstalled? Why is this necessary? I feel like there has to be a better way than expecting registry edits to be committed and then read back out immediately.

伏妖词 2024-10-12 04:39:18

我有同样的问题。我“安装”了一个 python 工具和环境,并在注册表中创建了一些系统变量。要刷新注册表,我执行以下操作:

def RefreshEnv():
    HWND_BROADCAST = 0xFFFF
    WM_SETTINGCHANGE = 0x1A

    SMTO_ABORTIFHUNG = 0x0002

    result = ctypes.c_long()
    SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
    SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, u'Environment',
                        SMTO_ABORTIFHUNG, 5000, ctypes.byref(result))

此方法没有像我预期的那样刷新注册表。我仍然需要打开窗口来编辑Windows中的系统变量,然后单击确定来刷新它们。否则,我安装的工具在尝试捕获环境变量时会因 KeyError 崩溃。

我不知道上面的 Refresh 功能是否会对您有所帮助(我猜不会),但至少这是一次尝试。

I have kind the same problem. I "install" a python tool and environment and create some system variables in the registry. To refresh the registry I do the following:

def RefreshEnv():
    HWND_BROADCAST = 0xFFFF
    WM_SETTINGCHANGE = 0x1A

    SMTO_ABORTIFHUNG = 0x0002

    result = ctypes.c_long()
    SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
    SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, u'Environment',
                        SMTO_ABORTIFHUNG, 5000, ctypes.byref(result))

This method is not refreshing the registry like I expected. I still have to open the window to edit the system variables in Windows and just click OK to refresh them. Otherwise my installed tools are crashing with an KeyError while trying to catch the environment variables.

I don't know if the Refresh function abovee will help you (I guess not), but at least it's a try.

幼儿园老大 2024-10-12 04:39:18

您可以使用以下任一方法:

  1. 只需使用 SysInternal 的 Process Explorer,或者
  2. 如果您有 chocolatey安装后,您只需在 PowerShell 中输入 refreshenv 即可。

You can use either of:

  1. Just restart windows explorer with SysInternal's Process Explorer, or
  2. If you have chocolatey installed, you can just type refreshenv in a PowerShell.
巷雨优美回忆 2024-10-12 04:39:18

我正在修改注册表项并希望在不重新启动系统的情况下读取该值。

如果刷新屏幕(F5 按钮),我可以手动阅读,但是你能让我知道如何通过 python 捕获它吗?

I am modifying the registry key and want to read that values without restarting the system.

I am able to read manually if I refresh the screen (F5 Button), but could you let me know how to capture this through python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文