当前位置: 首页>>代码示例>>Python>>正文


Python winreg.ConnectRegistry方法代码示例

本文整理汇总了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),
        ) 
开发者ID:python-poetry,项目名称:poetry,代码行数:26,代码来源:get-poetry.py

示例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 
开发者ID:borisbabic,项目名称:browser_cookie3,代码行数:19,代码来源:__init__.py

示例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 
开发者ID:kylebarron,项目名称:stata_kernel,代码行数:21,代码来源:utils.py

示例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 
开发者ID:adb014,项目名称:nsf2x,代码行数:25,代码来源:mapiex.py

示例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 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:24,代码来源:local.py

示例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() 
开发者ID:mechboxes,项目名称:mech,代码行数:23,代码来源:vmrun.py

示例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 
开发者ID:Thomasedv,项目名称:Grabber,代码行数:18,代码来源:utilities.py

示例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) 
开发者ID:coala,项目名称:coala-quickstart,代码行数:11,代码来源:store_env_in_registry.py

示例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 
开发者ID:python-poetry,项目名称:poetry,代码行数:8,代码来源:get-poetry.py

示例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 
开发者ID:gera2ld,项目名称:async_dns,代码行数:28,代码来源:nt.py

示例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 
开发者ID:turingsec,项目名称:marsnake,代码行数:29,代码来源:win_sec_check.py

示例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() 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:11,代码来源:tzwin.py

示例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 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:11,代码来源:tzwin.py

示例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] 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:32,代码来源:tzwin.py

示例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 
开发者ID:bartok765,项目名称:galaxy_blizzard_plugin,代码行数:34,代码来源:local_games.py


注:本文中的winreg.ConnectRegistry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。