本文整理匯總了Python中winreg.ConnectRegistry方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.ConnectRegistry方法的具體用法?Python winreg.ConnectRegistry怎麽用?Python winreg.ConnectRegistry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.ConnectRegistry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: set_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def set_windows_path_var(self, value):
import ctypes
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, value)
# Tell other processes to update their environment
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x1A
SMTO_ABORTIFHUNG = 0x0002
result = ctypes.c_long()
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
SendMessageTimeoutW(
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
u"Environment",
SMTO_ABORTIFHUNG,
5000,
ctypes.byref(result),
)
示例2: windows_group_policy_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [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: win_find_path
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def win_find_path():
import winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_CLASSES_ROOT)
subkeys = [
r'Stata16Do\shell\do\command', r'Stata15Do\shell\do\command',
r'Stata14Do\shell\do\command', r'Stata13Do\shell\do\command',
r'Stata12Do\shell\do\command']
fpath = ''
for subkey in subkeys:
try:
key = winreg.OpenKey(reg, subkey)
fpath = winreg.QueryValue(key, None).split('"')[1]
except FileNotFoundError:
pass
if fpath:
break
return fpath
示例4: CoCreateInstanceC2R
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [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: is_installed
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [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
示例6: get_win32_executable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [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()
示例7: get_win_accent_color
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def get_win_accent_color():
"""
Return the Windows 10 accent color used by the user in a HEX format
Windows specific
"""
# Open the registry
registry = ConnectRegistry(None, HKEY_CURRENT_USER)
key = OpenKey(registry, r'Software\Microsoft\Windows\DWM')
key_value = QueryValueEx(key, 'AccentColor')
accent_int = key_value[0]
accent_hex = hex(accent_int) # Remove FF offset and convert to HEX again
accent_hex = str(accent_hex)[4:] # Remove prefix
accent = accent_hex[4:6] + accent_hex[2:4] + accent_hex[0:2]
return '#' + accent
示例8: set_envvar_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [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)
示例9: get_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def get_windows_path_var(self):
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
path, _ = winreg.QueryValueEx(key, "PATH")
return path
示例10: get_nameservers
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def get_nameservers():
'''
Get nameservers from Windows Registry.
'''
nameservers = []
hlm = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
servers = _nt_read_key(hlm, r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters')
if servers is not None:
nameservers.extend(servers)
interfaces = winreg.OpenKey(
hlm, r'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces')
i = 0
while True:
try:
guid = winreg.EnumKey(interfaces, i)
i += 1
if not _nt_is_enabled(hlm, guid):
continue
servers = _nt_read_key(interfaces, guid)
if servers is not None:
nameservers.extend(servers)
except EnvironmentError:
break
interfaces.Close()
hlm.Close()
return nameservers
示例11: QueryUACLevel
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def QueryUACLevel():
if sys.platform != 'win32':
return -1
i, consentPromptBehaviorAdmin, enableLUA, promptOnSecureDesktop = 0, None, None, None
try:
Registry = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
RawKey = _winreg.OpenKey(Registry, "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System")
except:
return -1
while True:
try:
name, value, type = _winreg.EnumValue(RawKey, i)
if name == "ConsentPromptBehaviorAdmin": consentPromptBehaviorAdmin = value
elif name == "EnableLUA": enableLUA = value
elif name == "PromptOnSecureDesktop": promptOnSecureDesktop = value
i+=1
except WindowsError:
break
if consentPromptBehaviorAdmin == 2 and enableLUA == 1:
return 3
elif consentPromptBehaviorAdmin == 5 and enableLUA == 1 and promptOnSecureDesktop == 1:
return 2
elif consentPromptBehaviorAdmin == 5 and enableLUA == 1 and promptOnSecureDesktop == 0:
return 1
elif enableLUA == 0:
return 0
return -1
示例12: _settzkeyname
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def _settzkeyname():
global TZKEYNAME
handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
try:
winreg.OpenKey(handle, TZKEYNAMENT).Close()
TZKEYNAME = TZKEYNAMENT
except WindowsError:
TZKEYNAME = TZKEYNAME9X
handle.Close()
示例13: list
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def list():
"""Return a list of all time zones known to the system."""
handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
tzkey = winreg.OpenKey(handle, TZKEYNAME)
result = [winreg.EnumKey(tzkey, i)
for i in range(winreg.QueryInfoKey(tzkey)[0])]
tzkey.Close()
handle.Close()
return result
示例14: __init__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def __init__(self, name):
self._name = name
handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
tzkey = winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
keydict = valuestodict(tzkey)
tzkey.Close()
handle.Close()
self._stdname = keydict["Std"].encode("iso-8859-1")
self._dstname = keydict["Dlt"].encode("iso-8859-1")
self._display = keydict["Display"]
# See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
tup = struct.unpack("=3l16h", keydict["TZI"])
self._stdoffset = -tup[0]-tup[1] # Bias + StandardBias * -1
self._dstoffset = self._stdoffset-tup[2] # + DaylightBias * -1
(self._stdmonth,
self._stddayofweek, # Sunday = 0
self._stdweeknumber, # Last = 5
self._stdhour,
self._stdminute) = tup[4:9]
(self._dstmonth,
self._dstdayofweek, # Sunday = 0
self._dstweeknumber, # Last = 5
self._dsthour,
self._dstminute) = tup[12:17]
示例15: _find_classic_games
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import ConnectRegistry [as 別名]
def _find_classic_games(self):
classic_games = {}
log.debug("Looking for classic games")
if SYSTEM == Platform.WINDOWS:
try:
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
with winreg.OpenKey(reg, WINDOWS_UNINSTALL_LOCATION) as key:
for game in Blizzard.CLASSIC_GAMES:
log.debug(f"Checking if {game} is in registry ")
installed_game = self._add_classic_game(game, key)
if installed_game:
classic_games[game.uid] = installed_game
except OSError as e:
log.exception(f"Exception while looking for installed classic games {e}")
else:
proc = subprocess.run([LS_REGISTER,"-dump"], encoding='utf-8',stdout=subprocess.PIPE)
for game in Blizzard.CLASSIC_GAMES:
if game.bundle_id:
if game.bundle_id in proc.stdout:
classic_games[game.uid] = InstalledGame(
game,
'',
'1.0',
'',
'',
True
)
self.installed_classic_games_lock.acquire()
self.installed_classic_games = classic_games
self.installed_classic_games_lock.release()
if not self.parsed_classics:
self.parsed_classics = True