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


Python _winreg.OpenKey方法代码示例

本文整理汇总了Python中_winreg.OpenKey方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.OpenKey方法的具体用法?Python _winreg.OpenKey怎么用?Python _winreg.OpenKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_winreg的用法示例。


在下文中一共展示了_winreg.OpenKey方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WIN_get_device_guid

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def WIN_get_device_guid(self):

		try:
			regkey = registry.OpenKey(registry.HKEY_LOCAL_MACHINE, self.WINDOWS_ADAPTER_KEY)
			for i in xrange(10000):
				key_name = registry.EnumKey(regkey, i)
				try:
					regsubkey = registry.OpenKey(regkey, key_name)
					component_id = registry.QueryValueEx(regsubkey, "ComponentId")[0]
					if component_id == self.TUNTAP_COMPONENT_ID:
						return registry.QueryValueEx(regsubkey, 'NetCfgInstanceId')[0]
				except WindowsError as e:
					pass
					continue
		except Exception as e:
			pass
			return None

		return None 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:21,代码来源:interface.py

示例2: _open_windows_native_key

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def _open_windows_native_key(self, key, sub_key):
        """
        Opens a windows registry key using the OS bitness-based version of the
        registry view.
        This method eventually calls the _winreg.OpenKey() method.

        This is useful because if we're running a 32-bit python interpreter, by
        default _winreg accesses the 32-bit registry view. This is a problem on
        64-bit OSes as it limits us to registries of 32-bit applications.
        """
        import _winreg

        python_bitness, linkage = platform.architecture()

        # If we're running 32-bit python, by default _winreg accesses the
        # 32-bit registry view. This is a problem on 64-bit OSes.
        if python_bitness == '32bit' and platform.machine().endswith('64'):
            # Force _winreg to access the 64-bit registry view with the access
            # map as _winreg.KEY_WOW64_64KEY
            return _winreg.OpenKey(key, sub_key, 0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY)
        else:
            return _winreg.OpenKey(key, sub_key)

        return key 
开发者ID:ni,项目名称:python_labview_automation,代码行数:26,代码来源:labview.py

示例3: getPathFromRegistry

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def getPathFromRegistry():
    registryPath = r"Software\Microsoft\Windows\CurrentVersion\App Paths\trelby.exe"

    try:
        import _winreg

        regPathKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, registryPath)
        regPathValue, regPathType = _winreg.QueryValueEx(regPathKey, "Path")

        if regPathType == _winreg.REG_SZ:
            return regPathValue
        else:
            raise TypeError

    except:
        wx.MessageBox("There was an error reading the following registry key: %s.\n"
                      "You may need to reinstall the program to fix this error." %
                      registryPath, "Error", wx.OK)
        sys.exit()

# convert s, which is returned from the wxWidgets GUI and is an Unicode
# string, to a normal string. 
开发者ID:trelby,项目名称:trelby,代码行数:24,代码来源:misc.py

示例4: _get_win_folder_from_registry

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def _get_win_folder_from_registry(csidl_name):
    """This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    """
    import _winreg

    shell_folder_name = {
        "CSIDL_APPDATA": "AppData",
        "CSIDL_COMMON_APPDATA": "Common AppData",
        "CSIDL_LOCAL_APPDATA": "Local AppData",
    }[csidl_name]

    key = _winreg.OpenKey(
        _winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
    )
    dir, type = _winreg.QueryValueEx(key, shell_folder_name)
    return dir 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:appdirs.py

示例5: _get_win_folder_from_registry

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def _get_win_folder_from_registry(csidl_name):
    """
    This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    """
    import _winreg

    shell_folder_name = {
        "CSIDL_APPDATA": "AppData",
        "CSIDL_COMMON_APPDATA": "Common AppData",
        "CSIDL_LOCAL_APPDATA": "Local AppData",
    }[csidl_name]

    key = _winreg.OpenKey(
        _winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
    )
    directory, _type = _winreg.QueryValueEx(key, shell_folder_name)
    return directory 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:appdirs.py

示例6: _get_win_folder_from_registry

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def _get_win_folder_from_registry(csidl_name):
    """This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    """
    if PY3:
      import winreg as _winreg
    else:
      import _winreg

    shell_folder_name = {
        "CSIDL_APPDATA": "AppData",
        "CSIDL_COMMON_APPDATA": "Common AppData",
        "CSIDL_LOCAL_APPDATA": "Local AppData",
    }[csidl_name]

    key = _winreg.OpenKey(
        _winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
    )
    dir, type = _winreg.QueryValueEx(key, shell_folder_name)
    return dir 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:appdirs.py

示例7: set_windows_path_var

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [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

示例8: _get_win_folder_from_registry

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def _get_win_folder_from_registry(csidl_name):
    """
    This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    """
    import _winreg

    shell_folder_name = {
        "CSIDL_APPDATA": "AppData",
        "CSIDL_COMMON_APPDATA": "Common AppData",
        "CSIDL_LOCAL_APPDATA": "Local AppData",
    }[csidl_name]

    key = _winreg.OpenKey(
        _winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
    )
    directory, _type = _winreg.QueryValueEx(key, shell_folder_name)
    return directory 
开发者ID:python-poetry,项目名称:poetry,代码行数:22,代码来源:appdirs.py

示例9: get_device_guid

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def get_device_guid():
    with reg.OpenKey(reg.HKEY_LOCAL_MACHINE, adapter_key) as adapters:
        try:
            for i in xrange(10000):
                key_name = reg.EnumKey(adapters, i)
                with reg.OpenKey(adapters, key_name) as adapter:
                    try:
                        component_id = reg.QueryValueEx(adapter, 'ComponentId')[0]
                        # print component_id
                        # if component_id == 'tap0801':
                        if component_id == 'tap0901':
                            regid = reg.QueryValueEx(adapter, 'NetCfgInstanceId')[0]
                            return 'regid:', regid
                    except WindowsError, err:
                        pass
        except WindowsError, err:
            pass 
开发者ID:alexsunday,项目名称:pyvpn,代码行数:19,代码来源:tun-ping-win.py

示例10: test_registry_read_error

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def test_registry_read_error(self):
        import _winreg

        class MockWinreg(object):
            def OpenKey(self, key, name):
                if key != _winreg.HKEY_CLASSES_ROOT:
                    raise WindowsError(5, "Access is denied")
                return _winreg.OpenKey(key, name)
            def __getattr__(self, name):
                return getattr(_winreg, name)

        mimetypes._winreg = MockWinreg()
        try:
            mimetypes.init()
        finally:
            mimetypes._winreg = _winreg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_mimetypes.py

示例11: win32_reg_read

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def win32_reg_read (self, keyname, path):
		try:
			import _winreg
			mode = _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY
			key = _winreg.OpenKey(keyname, path, 0, mode)
			count = _winreg.QueryInfoKey(key)[0]
		except:
			return None
		data = {}
		for i in range(count):
			try:
				name, value, tt = _winreg.EnumValue(key, i)
			except OSError as e:
				break
			data[name] = (tt, value) 
		return data 
开发者ID:skywind3000,项目名称:terminal,代码行数:18,代码来源:terminal.py

示例12: test_self_iat_hook_sucess

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def test_self_iat_hook_sucess(self):
        pythondll_mod = [m for m in windows.current_process.peb.modules if m.name.startswith("python") and m.name.endswith(".dll")][0]
        RegOpenKeyExA = [n for n in pythondll_mod.pe.imports['advapi32.dll'] if n.name == "RegOpenKeyExA"][0]

        hook_value = []

        @windows.hooks.RegOpenKeyExACallback
        def open_reg_hook(hKey, lpSubKey, ulOptions, samDesired, phkResult, real_function):
            hook_value.append((hKey, lpSubKey.value))
            phkResult[0] = 12345678
            return 0

        RegOpenKeyExA.set_hook(open_reg_hook)
        import _winreg
        open_args = (0x12345678, "MY_KEY_VALUE")
        k = _winreg.OpenKey(*open_args)
        self.assertEqual(k.handle, 12345678)
        self.assertEqual(hook_value[0], open_args) 
开发者ID:sogeti-esec-lab,项目名称:LKD,代码行数:20,代码来源:mytest.py

示例13: WIN_get_subinterface_name

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import OpenKey [as 别名]
def WIN_get_subinterface_name(self):
		IFACE_NAME_KEY = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\"
		NetCfgInstanceId = self.WIN_get_device_guid()

		try:
			regkey = registry.OpenKey(registry.HKEY_LOCAL_MACHINE, IFACE_NAME_KEY+NetCfgInstanceId+"\\Connection\\")
			iface_name = registry.QueryValueEx(regkey, "Name")[0]
		except WindowsError as e:
			common.internal_print("Cannot get interface name. Registry key cannot be found: {0}".format(e), -1)
			sys.exit(-1)

		return iface_name 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:14,代码来源:interface.py


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