本文整理汇总了Python中_winreg.OpenKeyEx方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.OpenKeyEx方法的具体用法?Python _winreg.OpenKeyEx怎么用?Python _winreg.OpenKeyEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_winreg
的用法示例。
在下文中一共展示了_winreg.OpenKeyEx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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() is 0:
return False
key = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
"AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
value = _winreg.EnumValue(key, 0)[1]
if value is not u"":
return True
else:
return False
except WindowsError:
return False
示例2: 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)
示例3: open
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def open(cls, *args, **kargs):
return _RegKeyDict(_winreg.OpenKeyEx(*args, **kargs))
示例4: subkey
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def subkey(self, name):
return _RegKeyDict(_winreg.OpenKeyEx(self.key, name))
示例5: __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)
示例6: 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
示例7: 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)
示例8: _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
示例9: 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
示例10: 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)
示例11: isWinNT
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def isWinNT(self):
"""Are we running in Windows NT?"""
if self.getType() == 'win32':
import _winreg
try:
k=_winreg.OpenKeyEx(_winreg.HKEY_LOCAL_MACHINE,
r'Software\Microsoft\Windows NT\CurrentVersion')
_winreg.QueryValueEx(k, 'SystemRoot')
return 1
except WindowsError:
return 0
# not windows NT
return 0
示例12: query_registry_value
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def query_registry_value(root, key_name, value):
try:
import winreg
except ImportError:
import _winreg as winreg
try:
with winreg.OpenKeyEx(root, key_name, 0, winreg.KEY_READ) as key:
return get_value_from_tuple(*winreg.QueryValueEx(key, value))
except OSError:
return None
示例13: win32_ver
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def win32_ver(release='', version='', csd='', ptype=''):
try:
from sys import getwindowsversion
except ImportError:
return release, version, csd, ptype
try:
from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
except ImportError:
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
winver = getwindowsversion()
maj, min, build = _get_real_winver(*winver[:3])
version = '{0}.{1}.{2}'.format(maj, min, build)
release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
_WIN32_CLIENT_RELEASES.get((maj, None)) or
release)
# getwindowsversion() reflect the compatibility mode Python is
# running under, and so the service pack value is only going to be
# valid if the versions match.
if winver[:2] == (maj, min):
try:
csd = 'SP{}'.format(winver.service_pack_major)
except AttributeError:
if csd[:13] == 'Service Pack ':
csd = 'SP' + csd[13:]
# VER_NT_SERVER = 3
if getattr(winver, 'product_type', None) == 3:
release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
_WIN32_SERVER_RELEASES.get((maj, None)) or
release)
key = None
try:
key = OpenKeyEx(HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
ptype = QueryValueEx(key, 'CurrentType')[0]
except:
pass
finally:
if key:
CloseKey(key)
return release, version, csd, ptype
示例14: win32_ver
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def win32_ver(release='', version='', csd='', ptype=''):
try:
from sys import getwindowsversion
except ImportError:
return release, version, csd, ptype
try:
from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
except ImportError:
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
winver = getwindowsversion()
maj, min, build = winver.platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(maj, min, build)
release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
_WIN32_CLIENT_RELEASES.get((maj, None)) or
release)
# getwindowsversion() reflect the compatibility mode Python is
# running under, and so the service pack value is only going to be
# valid if the versions match.
if winver[:2] == (maj, min):
try:
csd = 'SP{}'.format(winver.service_pack_major)
except AttributeError:
if csd[:13] == 'Service Pack ':
csd = 'SP' + csd[13:]
# VER_NT_SERVER = 3
if getattr(winver, 'product_type', None) == 3:
release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
_WIN32_SERVER_RELEASES.get((maj, None)) or
release)
key = None
try:
key = OpenKeyEx(HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
ptype = QueryValueEx(key, 'CurrentType')[0]
except:
pass
finally:
if key:
CloseKey(key)
return release, version, csd, ptype
示例15: win32_ver
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKeyEx [as 别名]
def win32_ver(release='', version='', csd='', ptype=''):
try:
from sys import getwindowsversion
except ImportError:
return release, version, csd, ptype
try:
from winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
except ImportError:
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE
winver = getwindowsversion()
maj, min, build = winver._platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(maj, min, build)
release = (_WIN32_CLIENT_RELEASES.get((maj, min)) or
_WIN32_CLIENT_RELEASES.get((maj, None)) or
release)
# getwindowsversion() reflect the compatibility mode Python is
# running under, and so the service pack value is only going to be
# valid if the versions match.
if winver[:2] == (maj, min):
try:
csd = 'SP{}'.format(winver.service_pack_major)
except AttributeError:
if csd[:13] == 'Service Pack ':
csd = 'SP' + csd[13:]
# VER_NT_SERVER = 3
if getattr(winver, 'product_type', None) == 3:
release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
_WIN32_SERVER_RELEASES.get((maj, None)) or
release)
key = None
try:
key = OpenKeyEx(HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
ptype = QueryValueEx(key, 'CurrentType')[0]
except:
pass
finally:
if key:
CloseKey(key)
return release, version, csd, ptype