# If GetCommandString returns the same string for all items then # the shell seems to ignore all but one. This is even true in # Win7 etc where there is no status bar (and hence this string seems # ignored) return "Hello from Python (cmd=%d)!!" % (cmd,) def DllRegisterServer(): import winreg key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, "Python.File\\shellex") subkey = winreg.CreateKey(key, "ContextMenuHandlers") subkey2 = winreg.CreateKey(subkey, "PythonSample") winreg.SetValueEx(subkey2, None, 0, winreg.REG_SZ, ShellExtension._reg_clsid_) print(ShellExtension._reg_desc_, "registration complete.") def DllUnregisterServer(): import winreg try: key = winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT, "Python.File\\shellex\\ContextMenuHandlers\\PythonSample") except WindowsError as details: import errno if details.errno != errno.ENOENT: raise print(ShellExtension._reg_desc_, "unregistration complete.") if __name__=='__main__': from win32com.server import register register.UseCommandLine(ShellExtension, finalize_register = DllRegisterServer, finalize_unregister = DllUnregisterServer)
def DllRegisterServer(): # Also need to register specially in: # HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches # See link at top of file. import winreg kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \ % (EmptyVolumeCache._reg_desc_,) key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, kn) winreg.SetValueEx(key, None, 0, winreg.REG_SZ, EmptyVolumeCache._reg_clsid_) def DllUnregisterServer(): import winreg kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \ % (EmptyVolumeCache._reg_desc_,) try: key = winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, kn) except WindowsError as details: import errno if details.errno != errno.ENOENT: raise print(EmptyVolumeCache._reg_desc_, "unregistration complete.") if __name__ == '__main__': from win32com.server import register register.UseCommandLine(EmptyVolumeCache, finalize_register=DllRegisterServer, finalize_unregister=DllUnregisterServer)
# register the context menu handler under the FolderViewSampleType type. keypath = "%s\\shellex\\ContextMenuHandlers\\%s" % (ContextMenu._context_menu_type_, ContextMenu._reg_desc_) key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, keypath) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ContextMenu._reg_clsid_) propsys.PSRegisterPropertySchema(get_schema_fname()) print ShellFolder._reg_desc_, "registration complete." def DllUnregisterServer(): import _winreg paths = [ "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\Namespace\\" + ShellFolder._reg_clsid_, "%s\\shellex\\ContextMenuHandlers\\%s" % (ContextMenu._context_menu_type_, ContextMenu._reg_desc_), ] for path in paths: try: _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, path) except WindowsError, details: import errno if details.errno != errno.ENOENT: print "FAILED to remove %s: %s" % (path, details) propsys.PSUnregisterPropertySchema(get_schema_fname()) print ShellFolder._reg_desc_, "unregistration complete." if __name__=='__main__': from win32com.server import register register.UseCommandLine(ShellFolder, ContextMenu, debug = debug, finalize_register = DllRegisterServer, finalize_unregister = DllUnregisterServer)
def DllRegisterServer(): import _winreg # Special ColumnProvider key key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\ShellEx\\ColumnHandlers\\" + \ str(ColumnProvider._reg_clsid_ )) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ColumnProvider._reg_desc_) print ColumnProvider._reg_desc_, "registration complete." def DllUnregisterServer(): import _winreg try: key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\ShellEx\\ColumnHandlers\\" + \ str(ColumnProvider._reg_clsid_) ) except WindowsError, details: import errno if details.errno != errno.ENOENT: raise print ColumnProvider._reg_desc_, "unregistration complete." if __name__ == '__main__': from win32com.server import register register.UseCommandLine(ColumnProvider, finalize_register=DllRegisterServer, finalize_unregister=DllUnregisterServer)
# 'Attributes' is an int stored as a binary! use struct attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \ shellcon.SFGAO_BROWSABLE import struct s = struct.pack("i", attr) winreg.SetValueEx(key, "Attributes", 0, winreg.REG_BINARY, s) print(ShellFolderRoot._reg_desc_, "registration complete.") def DllUnregisterServer(): import winreg try: key = winreg.DeleteKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \ "Explorer\\Desktop\\Namespace\\" + \ ShellFolderRoot._reg_clsid_) except WindowsError as details: import errno if details.errno != errno.ENOENT: raise print(ShellFolderRoot._reg_desc_, "unregistration complete.") if __name__ == '__main__': from win32com.server import register register.UseCommandLine(ShellFolderRoot, debug=debug, finalize_register=DllRegisterServer, finalize_unregister=DllUnregisterServer)
from win32com.server import exception, register import pythoncom import win32pdhutil import winerror class PerfMonQuery: _reg_verprogid_ = "Python.PerfmonQuery.1" _reg_progid_ = "Python.PerfmonQuery" _reg_desc_ = "Python Performance Monitor query object" _reg_clsid_ = "{64cef7a0-8ece-11d1-a65a-00aa00125a98}" _reg_class_spec_ = "win32com.servers.perfmon.PerfMonQuery" _public_methods_ = ['Query'] def Query(self, object, counter, instance=None, machine=None): try: return win32pdhutil.GetPerformanceAttributes(object, counter, instance, machine=machine) except win32pdhutil.error as exc: raise exception.Exception(desc=exc.strerror) except TypeError as desc: raise exception.Exception(desc=desc, scode=winerror.DISP_E_TYPEMISMATCH) if __name__ == '__main__': print("Registering COM server...") register.UseCommandLine(PerfMonQuery)
def RegisterNextID(): from win32com.server import register register.UseCommandLine(NextID)
print "Unregistration complete: %s" % IconOverlay._reg_desc_ def DllRegisterServer2(): print "Registering %s" % REG_KEY2 import _winreg key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, REG_PATH) subkey = _winreg.CreateKey(key, PendingIconOverlay._reg_progid_) _winreg.SetValueEx(subkey, None, 0, _winreg.REG_SZ, PendingIconOverlay._reg_clsid_) print "Registration complete: %s" % PendingIconOverlay._reg_desc_ def DllUnregisterServer2(): print "Unregistering %s" % REG_KEY2 import _winreg try: key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, r"%s\%s" % (REG_PATH, PendingIconOverlay._reg_progid_)) except WindowsError, details: import errno if details.errno != errno.ENOENT: raise print "Unregistration complete: %s" % PendingIconOverlay._reg_desc_ if __name__=='__main__': from win32com.server import register register.UseCommandLine(IconOverlay, finalize_register = DllRegisterServer, finalize_unregister = DllUnregisterServer) register.UseCommandLine(PendingIconOverlay, finalize_register = DllRegisterServer2, finalize_unregister = DllUnregisterServer2)
import win32api import win32con from win32com.server import register import iconOverlay key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Dachengyun') winreg.SetValueEx(key, 'path', 0, winreg.REG_SZ, os.getcwd()) winreg.SetValueEx(key, 'dbPath', 0, winreg.REG_SZ, os.path.join(os.getcwd(), 'data.db')) winreg.SetValueEx(key, 'iconPath', 0, winreg.REG_SZ, os.path.join(os.getcwd(), 'icon')) winreg.SetValueEx(key, 'serverPath', 0, winreg.REG_SZ, r'http://127.0.0.1:8000/') winreg.SetValueEx(key, 'fileMaxSize', 0, winreg.REG_SZ, '104857600') winreg.FlushKey(key) key.Close() register.UseCommandLine(iconOverlay.IconOverlayOk) win32api.RegSetValue( win32api.RegCreateKey(iconOverlay.IconOverlayOk._reg_remove_keys_[0][1], iconOverlay.IconOverlayOk._reg_remove_keys_[0][0]), None, win32con.REG_SZ, iconOverlay.IconOverlayOk._reg_clsid_) register.UseCommandLine(iconOverlay.IconOverlaySync) win32api.RegSetValue( win32api.RegCreateKey(iconOverlay.IconOverlaySync._reg_remove_keys_[0][1], iconOverlay.IconOverlaySync._reg_remove_keys_[0][0]), None, win32con.REG_SZ, iconOverlay.IconOverlaySync._reg_clsid_) os.system('taskkill /f /im explorer.exe & start explorer.exe')