本文整理匯總了Python中winreg.OpenKeyEx方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.OpenKeyEx方法的具體用法?Python winreg.OpenKeyEx怎麽用?Python winreg.OpenKeyEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.OpenKeyEx方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_windows_python_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def _get_windows_python_path(x64):
"""Get the path to Python.exe on Windows."""
parts = str(sys.version_info.major), str(sys.version_info.minor)
ver = ''.join(parts)
dot_ver = '.'.join(parts)
if x64:
path = (r'SOFTWARE\Python\PythonCore\{}\InstallPath'
.format(dot_ver))
fallback = r'C:\Python{}\python.exe'.format(ver)
else:
path = (r'SOFTWARE\WOW6432Node\Python\PythonCore\{}-32\InstallPath'
.format(dot_ver))
fallback = r'C:\Python{}-32\python.exe'.format(ver)
try:
key = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, path)
return winreg.QueryValueEx(key, 'ExecutablePath')[0]
except FileNotFoundError:
return fallback
示例2: windows_group_policy_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def windows_group_policy_path():
# we know that we're running under windows at this point so it's safe to do these imports
from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ
try:
root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome")
user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir")
if type_ == REG_EXPAND_SZ:
user_data_dir = os.path.expandvars(user_data_dir)
elif type_ != REG_SZ:
return None
except OSError:
return None
return os.path.join(user_data_dir, "Default", "Cookies")
# Code adapted slightly from https://github.com/Arnie97/chrome-cookies
示例3: get_all_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def get_all_values(self):
schema = {}
for subkey in self:
schema[subkey.name] = subkey.get_all_values()
key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags)
try:
with key:
for i in count():
vname, value, vtype = winreg.EnumValue(key, i)
value = get_value_from_tuple(value, vtype)
if value:
schema[vname or ''] = value
except OSError:
pass
return PythonWrappedDict(schema)
示例4: _init_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [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
示例5: _get_launcher_install_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def _get_launcher_install_path(self) -> Optional[str]:
if is_windows():
try:
for h_root in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE):
with winreg.OpenKey(h_root, r"Software\Microsoft\Windows\CurrentVersion\Uninstall") as h_apps:
for idx in range(winreg.QueryInfoKey(h_apps)[0]):
try:
with winreg.OpenKeyEx(h_apps, winreg.EnumKey(h_apps, idx)) as h_app_info:
def get_value(key):
return winreg.QueryValueEx(h_app_info, key)[0]
if get_value("DisplayName") == self._LAUNCHER_DISPLAY_NAME:
installer_path = get_value("InstallLocation")
if os.path.exists(str(installer_path)):
return installer_path
except (WindowsError, KeyError, ValueError):
continue
except (WindowsError, KeyError, ValueError):
logging.exception("Failed to get client install location")
return None
else:
return None
示例6: enable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [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)
示例7: get_start_time
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def get_start_time(self):
'''
@summary: Get's Crypter's start time from the registry, or creates it if it
doesn't exist
@return: The time that the ransomware began it's encryption operation, in integer epoch form
'''
# Try to open registry key
try:
reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION)
start_time = winreg.QueryValueEx(reg, "")[0]
winreg.CloseKey(reg)
# If failure, create the key
except WindowsError:
start_time = int(time.time())
reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION)
winreg.SetValue(reg, "", winreg.REG_SZ, str(start_time))
winreg.CloseKey(reg)
return start_time
示例8: __iter__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def __iter__(self):
subkey_names = []
try:
with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key:
for i in count():
subkey_names.append(winreg.EnumKey(key, i))
except OSError:
pass
return iter(self[k] for k in subkey_names)
示例9: get_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def get_value(self, value_name):
try:
with winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags) as key:
return get_value_from_tuple(*winreg.QueryValueEx(key, value_name))
except OSError:
return None
示例10: delete
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def delete(self):
for k in self:
k.delete()
try:
key = winreg.OpenKeyEx(self._root, None, 0, winreg.KEY_READ | self._flags)
except OSError:
return
with key:
winreg.DeleteKeyEx(key, self.subkey)
示例11: _get_sid_from_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def _get_sid_from_registry():
try:
import winreg
except ImportError:
import _winreg as winreg
var_names = ("%USERPROFILE%", "%HOME%")
current_user_home = next(iter(os.path.expandvars(v) for v in var_names if v), None)
root, subkey = (
winreg.HKEY_LOCAL_MACHINE,
r"Software\Microsoft\Windows NT\CurrentVersion\ProfileList",
)
subkey_names = []
value = None
matching_key = None
try:
with winreg.OpenKeyEx(root, subkey, 0, winreg.KEY_READ) as key:
for i in count():
key_name = winreg.EnumKey(key, i)
subkey_names.append(key_name)
value = query_registry_value(
root, r"{0}\{1}".format(subkey, key_name), "ProfileImagePath"
)
if value and value.lower() == current_user_home.lower():
matching_key = key_name
break
except OSError:
pass
if matching_key is not None:
return matching_key
示例12: get_network_card_info
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def get_network_card_info():
reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards")
info = []
for i in range(6):
try:
descp = _winreg.QueryValueEx(_winreg.OpenKeyEx(
reg, _winreg.EnumKey(reg, i)), 'Description')[0]
info.append(descp)
except:
break
return info
示例13: get_cpu_info
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def get_cpu_info():
reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor")
flag = True
model_name = ""
num = _winreg.QueryInfoKey(reg)[0]
reg2 = _winreg.OpenKeyEx(reg, _winreg.EnumKey(reg, 0))
model_name = _winreg.QueryValueEx(reg2, 'ProcessorNameString')[0]
return "{} *{}".format(model_name, num)
示例14: has_sound
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def has_sound(sound):
"""Find out if a particular event is configured with a default sound"""
try:
# Ask the mixer API for the number of devices it knows about.
# When there are no devices, PlaySound will fail.
if ctypes.windll.winmm.mixerGetNumDevs() == 0:
return False
key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
"AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
return winreg.EnumValue(key, 0)[1] != ""
except OSError:
return False
示例15: _find_vc2015
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKeyEx [as 別名]
def _find_vc2015():
try:
key = winreg.OpenKeyEx(
winreg.HKEY_LOCAL_MACHINE,
r"Software\Microsoft\VisualStudio\SxS\VC7",
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
)
except OSError:
log.debug("Visual C++ is not registered")
return None, None
best_version = 0
best_dir = None
with key:
for i in count():
try:
v, vc_dir, vt = winreg.EnumValue(key, i)
except OSError:
break
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
try:
version = int(float(v))
except (ValueError, TypeError):
continue
if version >= 14 and version > best_version:
best_version, best_dir = version, vc_dir
return best_version, best_dir