本文整理匯總了Python中winreg.DeleteKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.DeleteKey方法的具體用法?Python winreg.DeleteKey怎麽用?Python winreg.DeleteKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.DeleteKey方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _delete_key_if_empty
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
def _delete_key_if_empty(self, service):
key_name = self._key_for_service(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
示例2: uninstaller_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
def uninstaller_cleanup():
if sys.platform == 'win32':
try:
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
access=winreg.KEY_WRITE) as reg:
winreg.DeleteKey(reg, 'SimNIBS')
except FileNotFoundError:
pass
示例3: del_subkey
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
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)
示例4: del_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
def del_key(self):
try:
k = winreg.DeleteKey(self.key, self.subkey)
to_return = self._return_success(k)
self.current_key = None
except WindowsError as e:
to_return = self._return_error(str(e))
return to_return
示例5: restore
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
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:
return None
else:
try:
winreg.DeleteKey(k, "\\".join(
exist_sk + new_sk[:-i]))
except WindowsError as error:
return None
self.last_created['new_sk'] = None
self.last_created['existing_sk'] = None
self.last_created['key'] = None
return True
示例6: delete_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
def delete_key(self, key, subkey):
""" Deletes a particular key
"""
try:
return winreg.DeleteKey(key, subkey)
except WindowsError as error:
return None
示例7: _remove_jupyter_here
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import DeleteKey [as 別名]
def _remove_jupyter_here(all_users):
if all_users:
h_key_base = winreg.HKEY_LOCAL_MACHINE
install_type = "all users"
else:
h_key_base = winreg.HKEY_CURRENT_USER
install_type = "single user"
for terminal in ('qtconsole', 'notebook', 'lab'):
try:
winreg.DeleteKey(
h_key_base,
r'Software\Classes\Directory\shell\jupyter_%s_here%s\Command' % (
terminal, CONDA_ENV_LABEL.replace(" ", "_")))
winreg.DeleteKey(
h_key_base,
r'Software\Classes\Directory\shell\jupyter_%s_here%s' % (
terminal, CONDA_ENV_LABEL.replace(" ", "_")))
winreg.DeleteKey(
h_key_base,
r'Software\Classes\Directory\Background\shell\jupyter_%s_here%s\Command' % (
terminal, CONDA_ENV_LABEL.replace(" ", "_")))
winreg.DeleteKey(
h_key_base,
r'Software\Classes\Directory\Background\shell\jupyter_%s_here%s' % (
terminal, CONDA_ENV_LABEL.replace(" ", "_")))
print("Jupyter %s here%s context menu entry removed for %s." % (
terminal, CONDA_ENV_LABEL, install_type))
except FileNotFoundError:
# If this fails it is because it was not installed, so nothing to
# worry about.
pass