Python winreg 模块,DeleteKey() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用winreg.DeleteKey()

项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def unregister(classobj):
    import winreg
    subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
    try:
        hKey = winreg.CreateKey( winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
        subKey = winreg.DeleteValue( hKey, "ButtonText" )
        winreg.DeleteValue( hKey, "ClsidExtension" ) # for calling COM object
        winreg.DeleteValue( hKey, "CLSID" )
        winreg.DeleteValue( hKey, "Default Visible" )
        winreg.DeleteValue( hKey, "ToolTip" )
        winreg.DeleteValue( hKey, "Icon" )
        winreg.DeleteValue( hKey, "HotIcon" )
        winreg.DeleteKey( winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
    except WindowsError:
        print("Couldn't delete Standard toolbar regkey.")
    else:
        print("Deleted Standard toolbar regkey.")

#
# test implementation
#
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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 as 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.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllUnregisterServer():
    import winreg
    try:
        key = winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT,
                                "directory\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError as details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    try:
        key = winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT,
                                "*\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError as details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print(ShellExtension._reg_desc_, "unregistration complete.")
项目:start_jupyter_cm    作者:hyperspy    | 项目源码 | 文件源码
def remove_jupyter_here():
    for env in ('qtconsole', 'notebook'):
        try:
            winreg.DeleteKey(
                winreg.HKEY_CLASSES_ROOT,
                r'Directory\shell\jupyter_%s_here\Command' %
                env)
            winreg.DeleteKey(
                winreg.HKEY_CLASSES_ROOT,
                r'Directory\shell\jupyter_%s_here' %
                env)
            winreg.DeleteKey(
                winreg.HKEY_CLASSES_ROOT,
                r'Directory\Background\shell\jupyter_%s_here\Command' %
                env)
            winreg.DeleteKey(
                winreg.HKEY_CLASSES_ROOT,
                r'Directory\Background\shell\jupyter_%s_here' %
                env)
            print("Jupyter %s here context menu entry removed." % env)
        except:
            # If this fails it is because it was not installed, so nothing to
            # worry about.
            pass
项目:keyrings.alt    作者:jaraco    | 项目源码 | 文件源码
def _delete_key_if_empty(self, service):
        key_name = r'Software\%s\Keyring' % service
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0,
            winreg.KEY_ALL_ACCESS)
        try:
            winreg.EnumValue(key, 0)
            return
        except WindowsError:
            pass
        winreg.CloseKey(key)

        # it's empty; delete everything
        while key_name != 'Software':
            parent, sep, base = key_name.rpartition('\\')
            key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, parent, 0,
                winreg.KEY_ALL_ACCESS)
            winreg.DeleteKey(key, base)
            winreg.CloseKey(key)
            key_name = parent
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def DllUnregisterServer():
    import winreg
    try:
        key = winreg.DeleteKey(winreg.HKEY_CLASSES_ROOT,
                                "Python.File\\shellex\\IconHandler")
    except WindowsError as details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print(ShellExtension._reg_desc_, "unregistration complete.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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.")
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import winreg
    try:
        winreg.DeleteKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import winreg
    try:
        winreg.DeleteKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:keypirinha-plugins    作者:EhsanKia    | 项目源码 | 文件源码
def del_subkey(self,name):
        """Delete the named subkey, and any values or keys it contains."""
        self.sam |= KEY_WRITE
        subkey = self.get_subkey(name)
        subkey.clear()
        _winreg.DeleteKey(subkey.parent.hkey,subkey.name)
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def deleteRegKey(self, key):
        """Deletes a key from the Windows Registry

        @param key: The registry key that should be deleted. The key should include the section. Eg. "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"
        @type key: string
        """
        hkey, key = self._getHiveAndKey(key)
        aReg = reg.ConnectRegistry(None, hkey)
        reg.DeleteKey(aReg, key)