本文整理匯總了Python中winreg.CloseKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.CloseKey方法的具體用法?Python winreg.CloseKey怎麽用?Python winreg.CloseKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.CloseKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: config_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def config_win():
try:
import winreg as reg
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk')
reg.SetValue(key, '', reg.REG_SZ, 'URL:nzblnk')
reg.SetValueEx(key, 'URL Protocol', 0, reg.REG_SZ, '')
reg.CloseKey(key)
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk\\shell\\open\\command')
reg.SetValue(key, '', reg.REG_SZ, '"{0}" "%1"'.format(op.normpath(os.path.abspath(sys.executable))))
reg.CloseKey(key)
except (OSError, ImportError):
print(Col.FAIL + ' FAILED to setup registry link for NZBLNK scheme!' + Col.OFF)
sleep(wait_time)
sys.exit(2)
示例2: flush
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def flush(self):
"""Ensure that the key's data is flushed to disk.
Quoting the _winreg documentation:
It is not necessary to call FlushKey() to change a key. Registry
changes are flushed to disk by the registry using its lazy flusher.
Registry changes are also flushed to disk at system shutdown.
Unlike CloseKey(), the FlushKey() method returns only when all the
data has been written to the registry. An application should only
call FlushKey() if it requires absolute certainty that registry
changes are on disk.
If you don't know whether a FlushKey() call is required, it
probably isn't.
"""
_winreg.FlushKey(self.hkey)
示例3: is_using_dcs_steam_edition
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def is_using_dcs_steam_edition():
"""
Check if DCS World : Steam Edition version is installed on this computer
:return True if DCS Steam edition is installed,
-1 if DCS Steam Edition is registered in Steam apps but not installed,
False if never installed in Steam
"""
if not is_windows_os:
return False
try:
# Note : Steam App ID for DCS World is 223750
dcs_steam_app_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam\\Apps\\223750")
installed = winreg.QueryValueEx(dcs_steam_app_key, "Installed")
winreg.CloseKey(dcs_steam_app_key)
if installed[0] == 1:
return True
else:
return False
except FileNotFoundError as fnfe:
return False
示例4: is_using_dcs_standalone_edition
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def is_using_dcs_standalone_edition():
"""
Check if DCS World standalone edition is installed on this computer
:return True if Standalone is installed, False if it is not
"""
if not is_windows_os:
return False
try:
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
winreg.CloseKey(dcs_path_key)
return True
except FileNotFoundError as fnfe:
try:
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World OpenBeta")
winreg.CloseKey(dcs_path_key)
return True
except FileNotFoundError:
return False
示例5: _delete_key_if_empty
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [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
示例6: _init_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def _init_from_registry(cls):
if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
return
import winreg
for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
try:
hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
r'Software\Imagemagick\Current',
0, winreg.KEY_QUERY_VALUE | flag)
binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
winreg.CloseKey(hkey)
break
except Exception:
binpath = ''
if binpath:
for exe in ('convert.exe', 'magick.exe'):
path = os.path.join(binpath, exe)
if os.path.exists(path):
binpath = path
break
else:
binpath = ''
rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath
示例7: CoCreateInstanceC2R
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def CoCreateInstanceC2R (self, store, reg, clsid, iid) :
# Ugly code to find DLL in C2R version of COM object and get a COM
# object despite the fact that COM doesn't handle C2R
try:
# Get DLL to load from 2R register
aReg = winreg.ConnectRegistry(None, store)
aKey = winreg.OpenKey(aReg, reg, 0, winreg.KEY_READ | winreg.KEY_WOW64_64KEY)
dummy_n, IconvDLL, dummy_t = winreg.EnumValue(aKey, 0)
winreg.CloseKey(aKey)
winreg.CloseKey(aReg)
# Create OLE object from DLL
IconvOLE = ctypes.OleDLL(IconvDLL)
# Get COM Instance from OLE
clsid_class = uuid.UUID(str(clsid)).bytes_le
iclassfactory = uuid.UUID(str(pythoncom.IID_IClassFactory)).bytes_le
com_classfactory = ctypes.c_long(0)
IconvOLE.DllGetClassObject(clsid_class, iclassfactory, ctypes.byref(com_classfactory))
MyFactory = pythoncom.ObjectFromAddress(com_classfactory.value, pythoncom.IID_IClassFactory)
return MyFactory.CreateInstance (None, str(iid))
except:
return None
示例8: get_apps_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def get_apps_values(self, h_key, key_path):
key = winreg.OpenKey(h_key, key_path, 0, winreg.KEY_READ)
i = 0
name = ""
version = "???"
while True:
try:
subkey = winreg.EnumValue(key, i)
result = subkey[0]
if result == "DisplayName":
name = subkey[1]
elif result == "DisplayVersion":
version = subkey[1]
i+=1
except WindowsError as e:
break
if name != "":
data = name + " ---> " + version
print(data)
if self.file_open:
self.file_open.write(data + "\n")
winreg.CloseKey(key)
示例9: reg_list_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def reg_list_value(key, root=winreg.HKEY_LOCAL_MACHINE):
"""
列舉機碼下的所有值
"""
i = 0
values = {}
handle = winreg.OpenKey(root, key)
while True:
try:
(vname, value, _) = winreg.EnumValue(handle, i)
if vname == '':
vname = '(default)'
values[vname] = value
i += 1
except OSError:
# winreg.EnumValue(handle, i) 的 i 超出範圍
break
winreg.CloseKey(handle)
return values
示例10: _read_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def _read_registry(root,key,value):
if _is_py2:
import _winreg as winreg
else:
import winreg
try:
hkey = winreg.OpenKey(root, key)
except:
return None
try:
(val, typ) = winreg.QueryValueEx(hkey, value)
except:
winreg.CloseKey(hkey)
return None
winreg.CloseKey(hkey)
return val
示例11: get_win32_executable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def get_win32_executable():
if PY3:
import winreg
else:
import _winreg as winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
try:
key = winreg.OpenKey(reg, 'SOFTWARE\\VMware, Inc.\\VMware Workstation')
try:
return os.path.join(winreg.QueryValueEx(key, 'InstallPath')[0], 'vmrun.exe')
finally:
winreg.CloseKey(key)
except WindowsError:
key = winreg.OpenKey(reg, 'SOFTWARE\\WOW6432Node\\VMware, Inc.\\VMware Workstation')
try:
return os.path.join(winreg.QueryValueEx(key, 'InstallPath')[0], 'vmrun.exe')
finally:
winreg.CloseKey(key)
finally:
reg.Close()
return get_fallback_executable()
示例12: uninstall_all
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def uninstall_all():
"""uninstalls PyXLL from all installed Excel versions"""
for wow64_flags in (winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY):
for root in _root_keys.keys():
try:
flags = wow64_flags | winreg.KEY_READ
office_root = winreg.OpenKey(root, r"Software\Microsoft\Office", 0, flags)
except WindowsError:
continue
# look for all installed versions of Excel and uninstall PyXLL
i = 0
while True:
try:
subkey = winreg.EnumKey(office_root, i)
except WindowsError:
break
match = re.match("^(\d+(?:\.\d+)?)$", subkey)
if match:
office_version = match.group(1)
uninstall(office_root, office_version, wow64_flags)
i += 1
winreg.CloseKey(office_root)
示例13: __init__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def __init__(self, args):
self.listen = None
for option in args.listen:
protos = [x.name for x in option.protos]
if option.unix or 'ssl' in protos or 'secure' in protos:
continue
if 'http' in protos:
self.listen = option
break
if self.listen is None:
print('No server listen on localhost by http')
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.KEY, 0, winreg.KEY_ALL_ACCESS)
value, regtype = winreg.QueryValueEx(key, self.SUBKEY)
assert regtype == winreg.REG_BINARY
server = f'localhost:{self.listen.port}'.encode()
bypass = '<local>'.encode()
counter = int.from_bytes(value[4:8], 'little') + 1
value = value[:4] + struct.pack('<III', counter, 3, len(server)) + server + struct.pack('<I', len(bypass)) + bypass + b'\x00'*36
winreg.SetValueEx(key, self.SUBKEY, None, regtype, value)
winreg.CloseKey(key)
示例14: test_run_command_windows
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def test_run_command_windows(action):
run_command(action=action)
env_label = get_environment_label()
import winreg
if isadmin:
h_key_base = winreg.HKEY_LOCAL_MACHINE
else:
h_key_base = winreg.HKEY_CURRENT_USER
for terminal in ["qtconsole", "notebook", "lab"]:
key = rf'Software\Classes\Directory\shell\jupyter_{terminal}_here{env_label.replace(" ", "_")}\Command'
if action == "add" and shutil.which(f"jupyter-{terminal}") is not None:
# Check if we can open the key to test if the key is present.
registry_key = winreg.OpenKey(h_key_base, key)
winreg.CloseKey(registry_key)
else:
with pytest.raises(FileNotFoundError):
# If the key have been properly removed, we will expect
# a `FileNotFoundError` to be raised
winreg.OpenKey(h_key_base, key)
示例15: enable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def enable(self):
'''
@summary: Disables Windows Task Manager
'''
key_exists = False
# Try to read the key
try:
reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION)
disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0]
winreg.CloseKey(reg)
key_exists = True
except:
pass
# If key exists and is disabled, enable it
if key_exists and disabled:
reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
self.DISABLE_KEY_LOCATION,
0,
winreg.KEY_SET_VALUE)
winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000000)
winreg.CloseKey(reg)