python win32api registery key change
- by user340495
Hi,
I am trying to trigger an event every time a registry value is being modified.
import win32api
import win32event
import win32con
import _winreg
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Control Panel\Desktop',0,_winreg.KEY_READ)
sub_key = _winreg.CreateKey(key,'Wallpaper')
evt = win32event.CreateEvent(None,0,0,None)
win32api.RegNotifyChangeKeyValue(sub_key,1,win32api.REG_NOTIFY_CHANGE_ATTRIBUTES,evt,True)
ret_code=win32event.WaitForSingleObject(evt,3000)
if ret_code == win32con.WAIT_OBJECT_0:
print "CHANGED"
if ret_code == win32con.WAIT_TIMEOUT:
print "TIMED"
my problem is that this is never triggered , the event always time-out.
(the reg key I am trying to follow is the wallpaper)
[
please note I trigger the event by 1) manually changing the registry value in regedit 2) an automated script which run this :
from ctypes import windll
from win32con import *
windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,"C:\wall.jpg",SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
]
Thanks for any help in advance :)
EDIT:: sorry about formatting