當前位置: 首頁>>代碼示例>>Python>>正文


Python _winreg.CloseKey方法代碼示例

本文整理匯總了Python中_winreg.CloseKey方法的典型用法代碼示例。如果您正苦於以下問題:Python _winreg.CloseKey方法的具體用法?Python _winreg.CloseKey怎麽用?Python _winreg.CloseKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_winreg的用法示例。


在下文中一共展示了_winreg.CloseKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: flush

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def flush(self):
        """Ensure that the key's data is flushed to disk.

        Quoting the _winreg documentation:

          It is not necessary to call FlushKey() to change a key. Registry
          changes are flushed to disk by the registry using its lazy flusher.
          Registry changes are also flushed to disk at system shutdown. 
          Unlike CloseKey(), the FlushKey() method returns only when all the
          data has been written to the registry. An application should only
          call FlushKey() if it requires absolute certainty that registry
          changes are on disk.

          If you don't know whether a FlushKey() call is required, it
          probably isn't.

        """
        _winreg.FlushKey(self.hkey) 
開發者ID:NVDARemote,項目名稱:NVDARemote,代碼行數:20,代碼來源:regobj.py

示例2: readKey

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def readKey(self, hkey, key_name, value_name = '', ignore_errors = False):
        if sys.platform != 'win32':
            return None
        try:
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Opening', key_name, value_name
            full_key = _winreg.OpenKey(hkey, key_name, 0, _winreg.KEY_READ)
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Open returned', full_key
            value_data, value_type = _winreg.QueryValueEx(full_key, value_name)
            if DEBUG:
                print >> sys.stderr, 'win32regcheck: Read', value_data, value_type
            _winreg.CloseKey(full_key)
            return value_data
        except:
            if not ignore_errors:
                print_exc(file=sys.stderr)
                print_stack()
            return None 
開發者ID:alesnav,項目名稱:p2ptv-pi,代碼行數:21,代碼來源:win32regchecker.py

示例3: _get_install_path

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def _get_install_path():
		"""
		Returns installation path from registry.
		Available only on Windows
		"""
		if is_portable():
			return os.environ["XDG_CONFIG_HOME"]
		try:
			key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\SyncthingGTK")
			path, keytype = _winreg.QueryValueEx(key, "InstallPath")
			path = str(path)
			_winreg.CloseKey(key)
			return path
		except WindowsError:
			# This is really shouldn't happen. Use executable path.
			os.path.dirname(sys.executable) 
開發者ID:kozec,項目名稱:syncthing-gtk,代碼行數:18,代碼來源:tools.py

示例4: __init__

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [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: _read_registry

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def _read_registry(root,key,value):
    if _is_py2:
        import _winreg as winreg
    else:
        import winreg
    try:
        hkey = winreg.OpenKey(root, key)
    except:
        return None
    try:
        (val, typ) = winreg.QueryValueEx(hkey, value)
    except:
        winreg.CloseKey(hkey)
        return None
    winreg.CloseKey(hkey)
    return val 
開發者ID:intelxed,項目名稱:mbuild,代碼行數:18,代碼來源:msvs.py

示例6: get_win32_executable

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [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: registry_key

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def registry_key(key, subkey, value):
    """
    Create a new Windows Registry Key in HKEY_CURRENT_USER

    `Required`
    :param str key:         primary registry key name
    :param str subkey:      registry key sub-key name
    :param str value:       registry key sub-key value

    Returns True if successful, otherwise False

    """
    try:
        import _winreg
        reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE)
        _winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value)
        _winreg.CloseKey(reg_key)
        return True
    except Exception as e:
        log(e)
        return False 
開發者ID:malwaredllc,項目名稱:byob,代碼行數:23,代碼來源:util.py

示例8: _iter_files

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def _iter_files(rsa_key, base_dir=None):
    try:
        if isinstance(rsa_key, Crypto.PublicKey.RSA.RsaKey):
            if base_dir:
                if os.path.isdir(base_dir):
                    return os.path.walk(base_dir, lambda _, dirname, files: [globals()['tasks'].put_nowait((encrypt_file, (os.path.join(dirname, filename), rsa_key))) for filename in files], None)
                else:
                    util.log("Target directory '{}' not found".format(base_dir))
            else:
                cipher = Crypto.Cipher.PKCS1_OAEP.new(rsa_key)
                reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, globals()['registry_key'], 0, _winreg.KEY_READ)
                i = 0
                while True:
                    try:
                        filename, key, _ = _winreg.EnumValue(reg_key, i)
                        key = cipher.decrypt(base64.b64decode(key))
                        globals()['tasks'].put_nowait((decrypt_file, (filename, key)))
                        i += 1
                    except:
                        _winreg.CloseKey(reg_key)
                        break
    except Exception as e:
        util.log('{} error: {}'.format(_iter_files.__name__, str(e))) 
開發者ID:malwaredllc,項目名稱:byob,代碼行數:25,代碼來源:ransom.py

示例9: uninstall_all

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def uninstall_all():
    """uninstalls PyXLL from all installed Excel versions"""
    for wow64_flags in (winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY):
        for root in _root_keys.keys():
            try:
                flags = wow64_flags | winreg.KEY_READ
                office_root = winreg.OpenKey(root, r"Software\Microsoft\Office", 0, flags)
            except WindowsError:
                continue

            # look for all installed versions of Excel and uninstall PyXLL
            i = 0
            while True:
                try:
                    subkey = winreg.EnumKey(office_root, i)
                except WindowsError:
                    break

                match = re.match("^(\d+(?:\.\d+)?)$", subkey)
                if match:
                    office_version = match.group(1)
                    uninstall(office_root, office_version, wow64_flags)
                i += 1

            winreg.CloseKey(office_root) 
開發者ID:pyxll,項目名稱:pyxll-examples,代碼行數:27,代碼來源:uninstall.py

示例10: win32FontDirectory

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def win32FontDirectory( ):
    """Get User-specific font directory on Win32"""
    try:
        import _winreg
    except ImportError:
        return os.path.join(os.environ['WINDIR'], 'Fonts')
    else:
        k = _winreg.OpenKey(
            _winreg.HKEY_CURRENT_USER,
            r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
        )
        try:
            # should check that k is valid? How?
            return _winreg.QueryValueEx( k, "Fonts" )[0]
        finally:
            _winreg.CloseKey( k ) 
開發者ID:gltn,項目名稱:stdm,代碼行數:18,代碼來源:findsystem.py

示例11: GetInnoCompilerPath

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def GetInnoCompilerPath():
    try:
        key = _winreg.OpenKey(
            _winreg.HKEY_LOCAL_MACHINE,
            (
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"
                "Uninstall\\Inno Setup 5_is1"
            )
        )
        installPath = _winreg.QueryValueEx(key, "InstallLocation")[0]
        _winreg.CloseKey(key)
    except WindowsError:
        return None
    installPath = join(installPath, "ISCC.exe")
    if not exists(installPath):
        return None
    return installPath 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:19,代碼來源:InnoSetup.py

示例12: MyComputer

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def MyComputer(self):
        mc_reg = None
        try:
            mc_reg = _winreg.OpenKey(
                _winreg.HKEY_CLASSES_ROOT,
                "CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
            )
            value, type = _winreg.QueryValueEx(mc_reg, "LocalizedString")
            dll = os.path.split(value.split(",")[0][1:])[1]
            index = -1*int(value.split(",")[1])
            myComputer = LoadString(LoadLibrary(dll), index)
        except:
            myComputer = self.text.myComp
        if mc_reg:
            _winreg.CloseKey(mc_reg)
        return myComputer 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:18,代碼來源:__init__.py

示例13: GetMpcHcPath

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def GetMpcHcPath(self):
        """
        Get the path of MPC-HC's installation directory through querying
        the Windows registry.
        """
        try:
            if "PROCESSOR_ARCHITEW6432" in environ:
                args = [_winreg.HKEY_CURRENT_USER,
                    "Software\MPC-HC\MPC-HC"]
                args.extend((0, _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY))
            else:
                args = [_winreg.HKEY_CURRENT_USER,
                    "Software\Gabest\Media Player Classic"]
            mpc = _winreg.OpenKey(*args)
            mpcPath =_winreg.QueryValueEx(mpc, "ExePath")[0]
            _winreg.CloseKey(mpc)
        except WindowsError:
            mpcPath = None
        return mpcPath 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:21,代碼來源:__init__.py

示例14: RunEmailClient

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def RunEmailClient(text):
    """Get the path of default email client through querying the
        Windows registry. """
    try:
        em_reg = _winreg.OpenKey(
            _winreg.HKEY_CLASSES_ROOT,
            "\\mailto\\shell\\open\\command"
        )
        EmPath = _winreg.EnumValue(em_reg,0)[1]
        _winreg.CloseKey(em_reg)
        EmPath = EmPath.split('"')[1]
    except:
        eg.PrintError(text.error9)
    else:
        head, tail = os.path.split(EmPath)
        win32api.ShellExecute(
            0,
            None,
            tail,
            None,
            head,
            1
        )
#=============================================================================== 
開發者ID:EventGhost,項目名稱:EventGhost,代碼行數:26,代碼來源:__init__.py

示例15: get_system_fontdirs

# 需要導入模塊: import _winreg [as 別名]
# 或者: from _winreg import CloseKey [as 別名]
def get_system_fontdirs():
    """
    The function detects system font directories according to detected 
    system type.
    """
    if system.get_os_family() == system.LINUX:
        home = os.path.expanduser('~')
        return ['/usr/share/fonts', os.path.join(home, '.fonts')]
    if system.get_os_family() == system.WINDOWS:
        try:
            import _winreg
        except ImportError:
            return [os.path.join(os.environ['WINDIR'], 'Fonts'), ]
        else:
            k = _winreg.OpenKey(
                _winreg.HKEY_CURRENT_USER,
                r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
            )
            try:
                return [_winreg.QueryValueEx(k, "Fonts")[0], ]
            finally:
                _winreg.CloseKey(k)
    if system.get_os_family() == system.MACOSX:
        # FIXME: It's a stub. The paths should be more exact.
        return ['/', ] 
開發者ID:sk1project,項目名稱:uniconvertor,代碼行數:27,代碼來源:fs.py


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