windows 如何刷新注册表值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4315265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh registry value
提问by upendra kumar
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.
问题是卸载后,除非屏幕或 regedit 未刷新,否则它不会更改注册表值。只有刷新后我才能得到正确的值。
Could some one help me out to refresh the regedit in python codes.
有人可以帮我刷新python代码中的regedit吗?
Regards, upendra
问候,upendra
回答by Cody Gray
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.
也许更重要的是,你在这里想做什么?您是否正在尝试让您的卸载程序验证您的应用程序已被卸载?为什么这是必要的?我觉得必须有比期望提交注册表编辑然后立即读回更好的方法。
回答by MagSec
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:
我有同样的问题。我“安装”了一个 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))
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.
这种方法并没有像我预期的那样刷新注册表。我仍然需要打开窗口来编辑 Windows 中的系统变量,然后单击OK
刷新它们。否则我安装的工具KeyError
在尝试捕获环境变量时会崩溃。
I don't know if the Refresh
function abovee will help you (I guess not), but at least it's a try.
我不知道上面的Refresh
功能是否会帮助你(我猜不会),但至少这是一个尝试。
回答by not2qubit
You can use either of:
您可以使用以下任一项:
- Just restart windows explorer with SysInternal's
Process Explorer
, or - If you have chocolateyinstalled, you can just type
refreshenv
in a PowerShell.
- 只需使用SysInternal重新启动 Windows 资源管理器
Process Explorer
,或 - 如果您安装了Chocolatey,则只需输入
refreshenv
PowerShell。
回答by upendra
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.
如果我刷新屏幕(F5 按钮),我可以手动阅读,但是你能告诉我如何通过 python 捕获它。