开发者

How to refresh registry value

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开发者_JS百科. after refreshing only i am getting the correct value.

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

Regards, upendra


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜