當前位置: 首頁>>代碼示例>>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: get_arcgis_paths

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def get_arcgis_paths():
    """
    Use the windows registry to figure out the paths to the following folders:

    - bin
    - arcpy
    - scripts

    as subfolders of the installation directory.
    """
    import _winreg
    registry = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
    arcgis_version = get_arcgis_version()
    try:
        key = _winreg.OpenKey(registry, r"SOFTWARE\wow6432Node\ESRI\Desktop%s" % arcgis_version)
    except WindowsError:
        key = _winreg.OpenKey(registry, r"SOFTWARE\ESRI\Desktop%s" % arcgis_version)
    install_dir, _ = _winreg.QueryValueEx(key, 'InstallDir')
    paths = [os.path.join(install_dir, 'bin64'),
            os.path.join(install_dir, 'arcpy'),
            os.path.join(install_dir, 'scripts')]
    return paths 
開發者ID:architecture-building-systems,項目名稱:CityEnergyAnalyst,代碼行數:24,代碼來源:install_toolbox.py

示例3: get_arcgis_version

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def get_arcgis_version():
    """Check the registry for ArcGIS and return the version. Checks the following two locations:

    - HKLM\software\wow6432Node\esri\Arcgis\RealVersion
    - HKLM\SOFTWARE\ESRI\ArcGIS\RealVersion

    returns the version string as ``"major.minor"``, so ``"10.4"`` or ``"10.5"``
    """
    import _winreg
    registry = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
    try:
        key = _winreg.OpenKey(registry, r"software\wow6432Node\esri\Arcgis")
    except WindowsError:
        key = _winreg.OpenKey(registry, r"SOFTWARE\ESRI\ArcGIS")
    value, _ = _winreg.QueryValueEx(key, 'RealVersion')
    return '.'.join(value.split('.')[:2]) 
開發者ID:architecture-building-systems,項目名稱:CityEnergyAnalyst,代碼行數:18,代碼來源:install_toolbox.py

示例4: __init__

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def __init__(self):
        self.hkey={}
        for key in (k for k in dir(reg) if k.startswith('HKEY_')):
            try:
                chk = reg.ConnectRegistry(None, getattr(reg, key))
                inf = reg.QueryInfoKey(chk)
                reg.CloseKey(chk)
            except WindowsError: pass           # some keys may appear in _winreg but can't be reached
            else:
                hk = Hkey(key)
                try:
                    chk=hk.keys
                except WindowsError: pass       # some keys can be accessed but not enumerated
                else:                           # some keys work fine ...
                    name=key[5:].lower()
                    self.hkey[name]=hk          # for iterating
                    setattr(self, name, hk)     # for easy access 
開發者ID:ActiveState,項目名稱:code,代碼行數:19,代碼來源:recipe-502268.py

示例5: CheckRegistryKey

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def CheckRegistryKey(javaKey):
		""" Method checks for the java in the registry entries. """
		from _winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx

		path = None
		try:
			aReg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
			rk = OpenKey(aReg, javaKey)
			for i in range(1024):
				currentVersion = QueryValueEx(rk, "CurrentVersion")
				if currentVersion != None:
					key = OpenKey(rk, currentVersion[0])
					if key != None:
						path = QueryValueEx(key, "JavaHome")
						return path[0]
		except Exception, err:
			# TODO: Add Warning/Error messages in Logger.
			WriteUcsWarning("Not able to access registry.")
			return None 
開發者ID:CiscoUcs,項目名稱:UcsPythonSDK,代碼行數:21,代碼來源:UcsBase.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_labview_paths_windows

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def _get_labview_paths_windows(self):
        # Connect to the registry at the root of the LabVIEW key
        import _winreg
        reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)

        installed_lv_paths = []
        # Iterate over all subkeys until you find one that isn't a version
        # number.  Each subkey represents a currently installed version of
        # LabVIEW. We want to pull from that the key indicating its install
        # path. We put each one into an array
        for root_key in [r"SOFTWARE\Wow6432Node\National Instruments\LabVIEW",
                         r"SOFTWARE\National Instruments\LabVIEW"]:
            try:
                key = self._open_windows_native_key(reg, root_key)
                i = 0
                current_lv_version = _winreg.EnumKey(key, i)
                while current_lv_version.find('.') != -1:
                    try:
                        current_lv_reg_key = self._open_windows_native_key(
                            reg, root_key + "\\" + current_lv_version)
                        value, key_type = _winreg.QueryValueEx(
                            current_lv_reg_key, "PATH")
                    except WindowsError as e:
                        if e.errno == 2:
                            pass
                    else:
                        installed_lv_paths.append(value)
                    finally:
                        i += 1
                        try:
                            current_lv_version = _winreg.EnumKey(key, i)
                        except (IOError, WindowsError):
                            break
            except WindowsError as e:
                # If the key doesn't exist LabVIEW may not be installed.  We
                # can safely ignore this error
                pass

        return installed_lv_paths 
開發者ID:ni,項目名稱:python_labview_automation,代碼行數:41,代碼來源:labview.py

示例8: _get_active_labview_windows

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def _get_active_labview_windows(self):
        # Connect to the registry at the root of the LabVIEW key
        import _winreg

        reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
        try:
            key = self._open_windows_native_key(
                reg, r"SOFTWARE\National Instruments\LabVIEW\CurrentVersion")
            value, key_type = _winreg.QueryValueEx(key, "PATH")
        except WindowsError:
            key = self._open_windows_native_key(
                reg,
                r"SOFTWARE\Wow6432Node\National Instruments\LabVIEW\CurrentVersion")
            value, key_type = _winreg.QueryValueEx(key, "PATH")
        return value 
開發者ID:ni,項目名稱:python_labview_automation,代碼行數:17,代碼來源:labview.py

示例9: 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

示例10: 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

示例11: break_sopcast

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def break_sopcast():
    if xbmc.getCondVisibility('system.platform.windows'):
        import _winreg
        aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
        try:
            aKey = _winreg.OpenKey(aReg, r'SOFTWARE\SopCast\Player\InstallPath', 0, _winreg.KEY_READ)
            name, value, type = _winreg.EnumValue(aKey, 0)
            codec_file = os.path.join(os.path.join(value.replace("SopCast.exe", "")), 'codec', 'sop.ocx.old')
            _winreg.CloseKey(aKey)
            if xbmcvfs.exists(codec_file): xbmcvfs.rename(codec_file,
                                                          os.path.join(os.path.join(value.replace("SopCast.exe", "")),
                                                                       'codec', 'sop.ocx'))
        except:
            pass 
開發者ID:tvaddonsco,項目名稱:program.plexus,代碼行數:16,代碼來源:sopcast.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:ktraunmueller,項目名稱:Computable,代碼行數: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:ktraunmueller,項目名稱:Computable,代碼行數: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:ktraunmueller,項目名稱:Computable,代碼行數:32,代碼來源:tzwin.py

示例15: break_sopcast

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import ConnectRegistry [as 別名]
def break_sopcast():
	if xbmc.getCondVisibility('system.platform.windows'):
		import _winreg
		aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
		try:
			aKey = _winreg.OpenKey(aReg, r'SOFTWARE\SopCast\Player\InstallPath',0, _winreg.KEY_READ)
			name, value, type = _winreg.EnumValue(aKey, 0)
			codec_file = os.path.join(os.path.join(value.replace("SopCast.exe","")),'codec','sop.ocx.old')
			_winreg.CloseKey(aKey)
			if xbmcvfs.exists(codec_file): xbmcvfs.rename(codec_file,os.path.join(os.path.join(value.replace("SopCast.exe","")),'codec','sop.ocx'))
		except:pass 
開發者ID:enen92,項目名稱:program.plexus,代碼行數:13,代碼來源:sopcast.py


注:本文中的_winreg.ConnectRegistry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。