本文整理匯總了Python中winreg.KEY_READ屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.KEY_READ屬性的具體用法?Python winreg.KEY_READ怎麽用?Python winreg.KEY_READ使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.KEY_READ屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _find_chrome_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def _find_chrome_win():
import winreg as reg
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE:
try:
reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ)
chrome_path = reg.QueryValue(reg_key, None)
reg_key.Close()
if not os.path.isfile(chrome_path):
continue
except WindowsError:
chrome_path = None
else:
break
return chrome_path
示例2: get_all_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def open_key(key):
"""Open the register key.
Args:
key (str): The key of register.
Returns:
str: The handle to the specified key.
"""
machine_type = platform.machine()
mappings = {"AMD64": winreg.KEY_WOW64_64KEY}
return winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
key,
access=winreg.KEY_READ | mappings.get(machine_type,
winreg.KEY_WOW64_32KEY),
)
示例4: CoCreateInstanceC2R
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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
示例5: get_apps_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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)
示例6: uninstall_all
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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)
示例7: _iterate_new_uninstall_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def _iterate_new_uninstall_keys(self):
for arch_key in self._ARCH_KEYS:
for hive in self._LOOKUP_REGISTRY_HIVES:
with winreg.OpenKey(hive, self._UNINSTALL_LOCATION, 0, winreg.KEY_READ | arch_key) as key:
subkeys = winreg.QueryInfoKey(key)[0]
cached_subkeys = self.__keys_count[hive | arch_key]
self.__keys_count[hive | arch_key] = subkeys
if subkeys <= cached_subkeys:
continue # same or lower number of installed programs since last refresh
logging.info(f'New keys in registry {hive | arch_key}: {subkeys}. Reparsing.')
for i in range(subkeys):
subkey_name = winreg.EnumKey(key, i)
if self._ignore_filter and self._ignore_filter(subkey_name):
logging.debug(f'Filtred out subkey: {subkey_name}')
continue
with winreg.OpenKey(key, subkey_name) as subkey:
yield (subkey_name, subkey)
示例8: _find_edge_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def _find_edge_win():
import winreg as reg
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe'
for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE:
try:
reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ)
edge_path = reg.QueryValue(reg_key, None)
reg_key.Close()
if not os.path.isfile(edge_path):
continue
except WindowsError:
edge_path = None
else:
break
return edge_path
示例9: cmder_setup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def cmder_setup():
global CMDER_SETUP
if CMDER_SETUP:
return
try:
akey = winreg.OpenKey(
winreg.HKEY_CLASSES_ROOT, "Directory\\shell\\Cmder\\command", 0, winreg.KEY_READ)
command = winreg.QueryValueEx(akey, "")[0]
conemu_base_dir = os.path.join(
RE_CMDER.match(command).group(1), "vendor", "conemu-maximus5", "ConEmu")
if os.path.exists(conemu_base_dir):
if conemu_base_dir not in os.environ["PATH"]:
os.environ["PATH"] = conemu_base_dir + ";" + os.environ["PATH"]
CMDER_SETUP = True
except Exception:
return
示例10: conemu_setup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def conemu_setup():
global CONEMU_SETUP
if CONEMU_SETUP:
return
try:
akey = winreg.OpenKey(
winreg.HKEY_CLASSES_ROOT, "Directory\\shell\\ConEmu Here\\command", 0, winreg.KEY_READ)
command = winreg.QueryValueEx(akey, "")[0]
conemu_base_dir = os.path.join(RE_CONEMU.match(command).group(1), "ConEmu")
if os.path.exists(conemu_base_dir):
if conemu_base_dir not in os.environ["PATH"]:
os.environ["PATH"] = conemu_base_dir + ";" + os.environ["PATH"]
CONEMU_SETUP = True
except Exception:
return
示例11: check_installed
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def check_installed():
ret = True
runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0, winreg.KEY_READ)
try:
winreg.QueryValueEx(runkey, "Px")
except:
ret = False
winreg.CloseKey(runkey)
return ret
示例12: _get_windows_uuid
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def _get_windows_uuid():
# pylint: disable=broad-except
# pylint: disable=no-member
uuid_value = None
try:
try: # Python 2
import _winreg as winreg
except ImportError: # Python 3
import winreg
registry = winreg.HKEY_LOCAL_MACHINE
address = 'SOFTWARE\\Microsoft\\Cryptography'
keyargs = winreg.KEY_READ | winreg.KEY_WOW64_64KEY
key = winreg.OpenKey(registry, address, 0, keyargs)
value = winreg.QueryValueEx(key, 'MachineGuid')
winreg.CloseKey(key)
uuid_value = value[0]
except Exception:
pass
if not uuid_value:
try:
import subprocess
output = subprocess.check_output(['vol', 'c:'])
output = output.split()
uuid_value = output[len(output) - 1:]
except Exception:
pass
return uuid_value
示例13: get_non_syspath_dirs
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [as 別名]
def get_non_syspath_dirs():
"""Returns a list containing the directories of the applications which are not found in the system path"""
# Try standard registry and the 32bit as well as 64bit mapping of it
for access_right in [_wr.KEY_READ, _wr.KEY_READ | _wr.KEY_WOW64_32KEY, _wr.KEY_READ | _wr.KEY_WOW64_64KEY]:
# Global instalations put their keys in HKLM (HKEY_LOCAL_MACHINE), user installations
# put their keys in HKCU (HKEY_CURRENT_USER)
for hkey in [_wr.HKEY_LOCAL_MACHINE, _wr.HKEY_CURRENT_USER]:
try:
key = _wr.OpenKey(hkey, INKSCAPE_REG_KEY, 0, access_right)
try:
# Inkscape stores its installation location in a Standard key -> ""
value, _ = _wr.QueryValueEx(key, "")
_wr.CloseKey(key)
dirname = _os.path.join(value, "bin")
return [dirname] if _os.path.isdir(dirname) else []
except WindowsError:
_wr.CloseKey(key)
except WindowsError:
pass
# Last chance: Guess at the two common locations
for dirname in ["C:\\Program Files\\Inkscape\\bin", "C:\\Program Files (x86)\\Inkscape\\bin"]:
if _os.path.isfile(_os.path.join(dirname, "inkscape.exe")):
return [dirname]
# Give up
return []
示例14: __iter__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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)
示例15: get_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_READ [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