I found some examples and topics on this forum about the way to implement an icon overlay handler with Python 2.7 & the win32com package but it does not work for me and I don't understand why.
I create the DLL and I have no error when I register it. I have also tried directly with the script but it's the same. It's like the class is never called.
Here is the code:
import win32traceutilfrom win32com.shell import shell, shellcon
import pythoncom
import winerror
import osREG_PATH =r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers'
REG_KEY = "GdIconOverlayTest"class GdClass:_reg_clsid_='{512AE200-F075-41E6-97DD-48ECA4311F2E}'_reg_progid_='GD.TestServer'_reg_desc_='gd desc'_public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf']_com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, pythoncom.IID_IDispatch]def __init__(self):passdef GetOverlayInfo(self):return (os.path.abspath(r'C:\icons\test.ico'), 0, shellcon.ISIOI_ICONFILE)def GetPriority(self):return 0def IsMemberOf(self, fname, attributes):print('ismemberOf', fname, os.path.basename(fname))if os.path.basename(fname) == "hello.text":return winerror.S_OKreturn winerror.E_FAILdef DllRegisterServer():print "Registering %s" % REG_KEYimport _winregkey = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, REG_PATH)subkey = _winreg.CreateKey(key, GdClass._reg_progid_)_winreg.SetValueEx(subkey, None, 0, _winreg.REG_SZ, GdClass._reg_clsid_)print "Registration complete: %s" % GdClass._reg_desc_def DllUnregisterServer():print "Unregistering %s" % REG_KEYimport _winregtry:key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, r"%s\%s" % (REG_PATH, GdClass._reg_progid_))except WindowsError, details:import errnoif details.errno != errno.ENOENT:raiseprint "Unregistration complete: %s" % GdClass._reg_desc_if __name__=='__main__':from win32com.server import registerregister.UseCommandLine(GdClass,finalize_register = DllRegisterServer,finalize_unregister = DllUnregisterServer)
Hi and thanks for your answer. I have tested with a log file and also win32traceutil. The registration/unregitration messages are logged. The registry entries are also created under:
1/HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\GD.TestServer 2/ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved 3/ directly under class root.
I have also added some logs inside the methods getOverlayInfo, GetPriority and isMemberOf but I can't see a trace when I browse through the explorer.
My configuration is: Python 2.7 pywin32-214.win32-py2.7.exe Windows XP SP 2
You can download all the code here: