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

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

项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
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
#
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def rdelete(self, key, subkey):
        """ Recursively delete a Windows registry key.
        This function will remove a key, even if it
        has child keys. There is no equivalent in
        _winreg. """

        if type(key) is str:
            hkey = Registry.map_key(key)
        elif type(key) is Registry.RegistryKey:
            hkey = key.getkey()
        else:
            hkey = key

        if type(subkey) is str:
            subkey  = self.open(hkey, subkey)

        # test2
        childkeys = subkey.keys()
        for keyname in childkeys:
            # print 'Child=>',keyname
            childkey = self.open(subkey.getkey(), keyname)
            self.rdelete(subkey, childkey)

        # print subkey.getkeyname()
        wreg.DeleteKey(hkey, subkey.getkeyname())
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
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."
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "directory\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "*\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import _winreg
    try:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
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
#
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "directory\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "*\\shellex\\CopyHookHandlers\\" +
                            ShellExtension._reg_desc_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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
#
项目: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
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __del_keys(self):
        'Private class method.'
        try:
            while True:
                _winreg.DeleteKey(self.__self, _winreg.EnumKey(self.__self, 0))
        except EnvironmentError:
            pass
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __delitem__(self, key):
        'Delete the specified key.'
        _winreg.DeleteKey(self.__self, key)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __del_keys(self):
        'Private class method.'
        try:
            while True:
                _winreg.DeleteKey(self.__key, _winreg.EnumKey(self.__key, 0))
        except EnvironmentError:
            pass
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __delitem__(self, key):
        'Delete the specified key.'
        _winreg.DeleteKey(self.__key, key)
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __del_keys(self):
        'Private class method.'
        try:
            while True:
                _winreg.DeleteKey(self.__key, _winreg.EnumKey(self.__key, 0))
        except EnvironmentError:
            pass
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def delete(self, key, subkey):
        """ Deletes a windows registry key. Same
        as DeleteKey of _winreg """

        if type(key) is str:
            hkey = self.map_key(key)
        else:
            hkey = key

        if not hkey: raise RegistryError,"could not find registry key for %s" % key
        try:
            wreg.DeleteKey(hkey, subkey)
        except EnvironmentError, e:
            raise RegistryError, e
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
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, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print EmptyVolumeCache._reg_desc_, "unregistration complete."
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolderRoot._reg_clsid_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellFolderRoot._reg_desc_, "unregistration complete."
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "Python.File\\shellex\\IconHandler")
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:Email_My_PC    作者:Jackeriss    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "Python.File\\shellex\\ContextMenuHandlers\\PythonSample")
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import _winreg
    try:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:uac-a-mola    作者:ElevenPaths    | 项目源码 | 文件源码
def restore(self, key, value=''):
        """ Restore to the last registry known state
        """
        if self.no_restore is False:
            new_sk = self.last_created['new_sk']
            k = self.last_created['key']
            exist_sk = self.last_created['existing_sk']

            self.del_value(key, value)

            if new_sk is not None:
                for i in range(len(new_sk)):
                    if i == 0:
                        try:
                            winreg.DeleteKey(k, "\\".join(exist_sk + new_sk))
                        except WindowsError as error:
                            pass
                    else:
                        try:
                            winreg.DeleteKey(k, "\\".join(
                                exist_sk + new_sk[:-i]))
                        except WindowsError as error:
                            pass

                self.last_created['new_sk'] = None
                self.last_created['existing_sk'] = None
                self.last_created['key'] = None
项目:uac-a-mola    作者:ElevenPaths    | 项目源码 | 文件源码
def delete_key(self, key, subkey):
        """ Deletes a particular key
        """
        try:
            return winreg.DeleteKey(key, subkey)
        except WindowsError as error:
            print "Error al eliminar la clave"
项目:csm    作者:gnzsystems    | 项目源码 | 文件源码
def remove_certificate(self, certificate):
        CONTAINS_SUBKEYS = 0
        registryHandles = []
        returnValue = False
        path = certificate["RegPath"].split("/")
        hiveName = path.pop(0)
        keyName = path.pop(-1)
        hive = reg.ConnectRegistry(None, self.regKeys[hiveName][0])
        registryHandle = reg.OpenKey(hive, self.regKeys[hiveName][1])
        self._log("Connected to registry at location: %s" % hiveName)
        for step in path:
            registryHandles.append(registryHandle)
            registryHandle = reg.OpenKey(registryHandle, step)
        try:
            deletionCandidate = reg.OpenKey(registryHandle, keyName)
            self._log("Querying deletion canditate: %s" % certificate["RegPath"])
            if not reg.QueryInfoKey(deletionCandidate)[CONTAINS_SUBKEYS]:
                self._log("Attempting to delete key: %s" % certificate["RegPath"])
                reg.CloseKey(deletionCandidate)
                reg.DeleteKey(registryHandle, keyName)
                self._log("Deleted key: %s" % certificate["RegPath"])
                returnValue = True
            else:
                self._error_log("Unable to delete key: %s.  Key  contains subkeys." % certificate["RegPath"])
                registryHandles.append(deletionCandidate)
                raise WindowsError
        except WindowsError as e:
            self._error_log("Unable to delete key: %s.  Windows error." % certificate["RegPath"])
            self._error_log("%s: %s" % (certificate["RegPath"], str(e)))
            pass
        self._log("Closing registry handles...")
        for handle in registryHandles:
            reg.CloseKey(handle)
        reg.CloseKey(hive)
        self._log("Registry handles closed.")
        return returnValue
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import _winreg
    try:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import _winreg
    try:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print EmptyVolumeCache._reg_desc_, "unregistration complete."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE,
                            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
                            "Explorer\\Desktop\\Namespace\\" + \
                            ShellFolderRoot._reg_clsid_)
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellFolderRoot._reg_desc_, "unregistration complete."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "Python.File\\shellex\\IconHandler")
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def DllUnregisterServer():
    import _winreg
    try:
        key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT,
                                "Python.File\\shellex\\ContextMenuHandlers\\PythonSample")
    except WindowsError, details:
        import errno
        if details.errno != errno.ENOENT:
            raise
    print ShellExtension._reg_desc_, "unregistration complete."
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def UnregisterAddin(klass):
    import _winreg
    try:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Excel\\Addins\\" + klass._reg_progid_)
    except WindowsError:
        pass
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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)
项目:maestro    作者:InWorldz    | 项目源码 | 文件源码
def __delitem__(self, key):
        # Delete a string value or a subkey, depending on the type
        try:
            item = self[key]
        except:
            return  # Silently ignore bad keys
        itemtype = type(item)
        if itemtype is str:
            _winreg.DeleteValue(self.keyhandle, key)
        elif isinstance(item, RegistryDict):
            # Delete everything in the subkey, then the subkey itself
            item.clear()
            _winreg.DeleteKey(self.keyhandle, key)
        else:
            raise ValueError, "Unknown item type in RegistryDict"
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def RegisterPythonwin(register=True):
    """ Add (or remove) Pythonwin to context menu for python scripts.
        ??? Should probably also add Edit command for pys files also.
        Also need to remove these keys on uninstall, but there's no function
            like file_created to add registry entries to uninstall log ???
    """
    import os, distutils.sysconfig

    lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
    classes_root=get_root_hkey()
    ## Installer executable doesn't seem to pass anything to postinstall script indicating if it's a debug build,
    pythonwin_exe = os.path.join(lib_dir, "Pythonwin", "Pythonwin.exe")
    pythonwin_edit_command=pythonwin_exe + ' /edit "%1"'

    keys_vals = [
        ('Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Pythonwin.exe', '', pythonwin_exe),
        ('Software\\Classes\\Python.File\\shell\\Edit with Pythonwin', 'command', pythonwin_edit_command),
        ('Software\\Classes\\Python.NoConFile\\shell\\Edit with Pythonwin', 'command', pythonwin_edit_command),
        ]

    try:
        if register:
            for key, sub_key, val in keys_vals:
                ## Since winreg only uses the character Api functions, this can fail if Python
                ##  is installed to a path containing non-ascii characters
                hkey = winreg.CreateKey(classes_root, key)
                if sub_key:
                    hkey = winreg.CreateKey(hkey, sub_key)
                winreg.SetValueEx(hkey, None, 0, winreg.REG_SZ, val)
                hkey.Close()
        else:
            for key, sub_key, val in keys_vals:
                try:
                    winreg.DeleteKey(classes_root, key)
                except OSError, why:
                    winerror = getattr(why, 'winerror', why.errno)
                    if winerror != 2: # file not found
                        raise
    finally:
        # tell windows about the change
        from win32com.shell import shell, shellcon
        shell.SHChangeNotify(shellcon.SHCNE_ASSOCCHANGED, shellcon.SHCNF_IDLIST, None, None)