本文整理匯總了Python中winreg.HKEY_LOCAL_MACHINE屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.HKEY_LOCAL_MACHINE屬性的具體用法?Python winreg.HKEY_LOCAL_MACHINE怎麽用?Python winreg.HKEY_LOCAL_MACHINE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.HKEY_LOCAL_MACHINE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: windows_group_policy_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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
示例2: _find_chrome_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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
示例3: win32InstalledFonts
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def win32InstalledFonts(directory=None, fontext='ttf'):
"""
Search for fonts in the specified font directory, or use the
system directories if none given. Additionally, it is searched for user
fonts installed. A list of TrueType font filenames are returned by default,
or AFM fonts if *fontext* == 'afm'.
"""
import winreg
if directory is None:
directory = win32FontDirectory()
fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)]
items = set()
# System fonts
items.update(_win32RegistryFonts(winreg.HKEY_LOCAL_MACHINE, directory))
# User fonts
for userdir in MSUserFontDirectories:
items.update(_win32RegistryFonts(winreg.HKEY_CURRENT_USER, userdir))
# Keep only paths with matching file extension.
return [str(path) for path in items if path.suffix.lower() in fontext]
示例4: QueryAutoCdRom
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def QueryAutoCdRom():
keypath=r'SYSTEM\CurrentControlSet\Services\cdrom'
try:
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,keypath)
return _winreg.QueryValueEx(key,'AutoRun')[0]
except:
return None
# def QueryHKCUNoDriveAutoRun():# 0-0x3FFFFFF
# keypath=r'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer'
# try:
# key=_winreg.OpenKey(_winreg.HKEY_CURRENT_USER,keypath)
# return _winreg.QueryValueEx(key,'NoDriveAutoRun ')[0]
# except:
# return None
# def QueryHKCUNoDriveTypeAutoRun():
# keypath=r'Software\Microsoft\Windows\CurrentVersion\Policies\Explorer'
# try:
# key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,keypath)
# return _winreg.QueryValueEx(key,'NoDriveTypeAutoRun ')[0]
# except:
# return None
示例5: open_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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),
)
示例6: _get_launcher_install_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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
示例7: reg_list_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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
示例8: is_installed
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def is_installed(self):
# Bethesda client is not available for macOs
if sys.platform != 'win32':
log.info("Platform is not compatible")
return False
path = None
try:
log.info("Connecting to hkey_local_machine key")
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
log.info(f"Opening key at {reg}, {BETTY_WINREG_LOCATION}")
with winreg.OpenKey(reg, BETTY_WINREG_LOCATION) as key:
path = winreg.QueryValueEx(key, "installLocation")[0]
log.info(f"Checking if path exists at {os.path.join(path, BETTY_LAUNCHER_EXE)}")
self.betty_client_path = path
return os.path.exists(os.path.join(path, BETTY_LAUNCHER_EXE))
except (OSError, KeyError):
self.betty_client_path = path
return False
except Exception as e:
self.betty_client_path = path
log.exception(f"Exception while checking if client is installed, assuming not installed {repr(e)}")
return False
示例9: _find_msvc_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def _find_msvc_in_registry(env,version):
if _is_py2:
import _winreg as winreg
else:
import winreg
vs_ver = str(version) + '.0'
vs_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Microsoft\\VisualStudio\\' + vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE, vs_key, 'ProductDir')
vc_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE, vc_key, 'ProductDir')
# On a 64-bit host, look for a 32-bit installation
if (not vs_dir or not vc_dir):
vs_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VS'
vc_key = 'SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\' + \
vs_ver + '\\Setup\\VC'
vs_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE,
vs_key, 'ProductDir')
vc_dir = _read_registry(winreg.HKEY_LOCAL_MACHINE,
vc_key, 'ProductDir')
return (vs_dir,vc_dir)
示例10: IsLavFilters
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def IsLavFilters():
''' Check if LavFilters is present '''
if windows:
software_list = WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_32KEY) + WinSoftwareInstalled(winreg.HKEY_LOCAL_MACHINE, winreg.KEY_WOW64_64KEY) + WinSoftwareInstalled(winreg.HKEY_CURRENT_USER, 0)
if not any('LAV Filters' in software['name'] for software in software_list):
# does not exist
return False
else:
cache = apt.Cache()
cache.open()
try:
#print("lav filters")
return cache["gst123"].is_installed
except Exception:
# does not exist
return False
return True
示例11: get_win32_executable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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: test_run_command_windows
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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)
示例13: set_envvar_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [as 別名]
def set_envvar_in_registry(envvar, value):
try:
import winreg
except ImportError:
import _winreg as winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
with winreg.OpenKey(reg, KEY, 0, winreg.KEY_ALL_ACCESS) as regkey:
winreg.SetValueEx(regkey, envvar, 0, winreg.REG_EXPAND_SZ, value)
示例14: _get_windows_uuid
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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
示例15: get_non_syspath_dirs
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import HKEY_LOCAL_MACHINE [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 []