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


Python winreg.CloseKey方法代碼示例

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


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

示例1: config_win

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def config_win():

    try:
        import winreg as reg
        key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk')
        reg.SetValue(key, '', reg.REG_SZ, 'URL:nzblnk')
        reg.SetValueEx(key, 'URL Protocol', 0, reg.REG_SZ, '')
        reg.CloseKey(key)

        key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk\\shell\\open\\command')
        reg.SetValue(key, '', reg.REG_SZ, '"{0}" "%1"'.format(op.normpath(os.path.abspath(sys.executable))))
        reg.CloseKey(key)

    except (OSError, ImportError):
        print(Col.FAIL + ' FAILED to setup registry link for NZBLNK scheme!' + Col.OFF)
        sleep(wait_time)
        sys.exit(2) 
開發者ID:nzblnk,項目名稱:nzb-monkey,代碼行數:19,代碼來源:nzblnkconfig.py

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

示例3: is_using_dcs_steam_edition

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def is_using_dcs_steam_edition():
    """
    Check if DCS World : Steam Edition version is installed on this computer
    :return True if DCS Steam edition is installed,
            -1 if DCS Steam Edition is registered in Steam apps but not installed,
            False if never installed in Steam
    """
    if not is_windows_os:
        return False
    try:
        # Note : Steam App ID for DCS World is 223750
        dcs_steam_app_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam\\Apps\\223750")
        installed = winreg.QueryValueEx(dcs_steam_app_key, "Installed")
        winreg.CloseKey(dcs_steam_app_key)
        if installed[0] == 1:
            return True
        else:
            return False
    except FileNotFoundError as fnfe:
        return False 
開發者ID:pydcs,項目名稱:dcs,代碼行數:22,代碼來源:installation.py

示例4: is_using_dcs_standalone_edition

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def is_using_dcs_standalone_edition():
    """
    Check if DCS World standalone edition is installed on this computer
    :return True if Standalone is installed, False if it is not
    """
    if not is_windows_os:
        return False
    try:
        dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
        winreg.CloseKey(dcs_path_key)
        return True
    except FileNotFoundError as fnfe:
        try:
            dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World OpenBeta")
            winreg.CloseKey(dcs_path_key)
            return True
        except FileNotFoundError:
            return False 
開發者ID:pydcs,項目名稱:dcs,代碼行數:20,代碼來源:installation.py

示例5: _delete_key_if_empty

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def _delete_key_if_empty(self, service):
        key_name = self._key_for_service(service)
        key = winreg.OpenKey(
            winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS
        )
        try:
            winreg.EnumValue(key, 0)
            return
        except WindowsError:
            pass
        winreg.CloseKey(key)

        # it's empty; delete everything
        while key_name != 'Software':
            parent, sep, base = key_name.rpartition('\\')
            key = winreg.OpenKey(
                winreg.HKEY_CURRENT_USER, parent, 0, winreg.KEY_ALL_ACCESS
            )
            winreg.DeleteKey(key, base)
            winreg.CloseKey(key)
            key_name = parent 
開發者ID:jaraco,項目名稱:keyrings.alt,代碼行數:23,代碼來源:Windows.py

示例6: _init_from_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def _init_from_registry(cls):
        if sys.platform != 'win32' or rcParams[cls.exec_key] != 'convert':
            return
        import winreg
        for flag in (0, winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY):
            try:
                hkey = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE,
                                        r'Software\Imagemagick\Current',
                                        0, winreg.KEY_QUERY_VALUE | flag)
                binpath = winreg.QueryValueEx(hkey, 'BinPath')[0]
                winreg.CloseKey(hkey)
                break
            except Exception:
                binpath = ''
        if binpath:
            for exe in ('convert.exe', 'magick.exe'):
                path = os.path.join(binpath, exe)
                if os.path.exists(path):
                    binpath = path
                    break
            else:
                binpath = ''
        rcParams[cls.exec_key] = rcParamsDefault[cls.exec_key] = binpath 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:25,代碼來源:animation.py

示例7: CoCreateInstanceC2R

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

示例8: get_apps_values

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def get_apps_values(self, h_key, key_path):
        key = winreg.OpenKey(h_key, key_path, 0, winreg.KEY_READ)
        i = 0
        name = ""
        version = "???"
        while True:
            try:
                subkey = winreg.EnumValue(key, i)
                result = subkey[0]
                if result == "DisplayName":
                    name = subkey[1]
                elif result == "DisplayVersion":
                    version = subkey[1]
                i+=1
            except WindowsError as e:
                break
        if name != "":
            data = name + " ---> " + version
            print(data)
            if self.file_open:
                self.file_open.write(data + "\n")
        winreg.CloseKey(key) 
開發者ID:Josue87,項目名稱:BoomER,代碼行數:24,代碼來源:get_applications.py

示例9: reg_list_value

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def reg_list_value(key, root=winreg.HKEY_LOCAL_MACHINE):
    """
    列舉機碼下的所有值
    """
    i = 0
    values = {}
    handle = winreg.OpenKey(root, key)

    while True:
        try:
            (vname, value, _) = winreg.EnumValue(handle, i)
            if vname == '':
                vname = '(default)'
            values[vname] = value
            i += 1
        except OSError:
            # winreg.EnumValue(handle, i) 的 i 超出範圍
            break

    winreg.CloseKey(handle)
    return values 
開發者ID:tacosync,項目名稱:skcom,代碼行數:23,代碼來源:helper.py

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

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

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

示例13: __init__

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def __init__(self, args):
		self.listen = None
		for option in args.listen:
			protos = [x.name for x in option.protos]
			if option.unix or 'ssl' in protos or 'secure' in protos:
				continue
			if 'http' in protos:
				self.listen = option
				break
		if self.listen is None:
			print('No server listen on localhost by http')
		import winreg
		key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.KEY, 0, winreg.KEY_ALL_ACCESS)
		value, regtype = winreg.QueryValueEx(key, self.SUBKEY)
		assert regtype == winreg.REG_BINARY
		server = f'localhost:{self.listen.port}'.encode()
		bypass = '<local>'.encode()
		counter = int.from_bytes(value[4:8], 'little') + 1
		value = value[:4] + struct.pack('<III', counter, 3, len(server)) + server + struct.pack('<I', len(bypass)) + bypass + b'\x00'*36
		winreg.SetValueEx(key, self.SUBKEY, None, regtype, value)
		winreg.CloseKey(key) 
開發者ID:qwj,項目名稱:python-proxy,代碼行數:23,代碼來源:sysproxy.py

示例14: test_run_command_windows

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def test_run_command_windows(action):
    run_command(action=action)
    env_label = get_environment_label()

    import winreg
    if isadmin:
        h_key_base = winreg.HKEY_LOCAL_MACHINE
    else:
        h_key_base = winreg.HKEY_CURRENT_USER
    for terminal in ["qtconsole", "notebook", "lab"]:
        key = rf'Software\Classes\Directory\shell\jupyter_{terminal}_here{env_label.replace(" ", "_")}\Command'
        if action == "add" and shutil.which(f"jupyter-{terminal}") is not None:
            # Check if we can open the key to test if the key is present.
            registry_key = winreg.OpenKey(h_key_base, key)
            winreg.CloseKey(registry_key)
        else:
            with pytest.raises(FileNotFoundError):
                # If the key have been properly removed, we will expect
                # a `FileNotFoundError` to be raised
                winreg.OpenKey(h_key_base, key) 
開發者ID:hyperspy,項目名稱:start_jupyter_cm,代碼行數:22,代碼來源:test_command.py

示例15: enable

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CloseKey [as 別名]
def enable(self):
        '''
        @summary: Disables Windows Task Manager
        '''
        key_exists = False
        
        # Try to read the key
        try:
            reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION)
            disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0]
            winreg.CloseKey(reg)
            key_exists = True
        except:
            pass
            
        # If key exists and is disabled, enable it
        if key_exists and disabled:
            reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                                  self.DISABLE_KEY_LOCATION,
                                  0,
                                  winreg.KEY_SET_VALUE)
            winreg.SetValueEx(reg, "DisableTaskMgr", 0,  winreg.REG_DWORD, 0x00000000)
            winreg.CloseKey(reg) 
開發者ID:sithis993,項目名稱:Crypter,代碼行數:25,代碼來源:TaskManager.py


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