Python winreg.ConnectRegistry() Examples

The following are 30 code examples of winreg.ConnectRegistry(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module winreg , or try the search function .
Example #1
Source File: __init__.py    From browser_cookie3 with GNU Lesser General Public License v3.0 7 votes vote down vote up
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 
Example #2
Source File: store_env_in_registry.py    From coala-quickstart with GNU Affero General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: get-poetry.py    From poetry with MIT License 6 votes vote down vote up
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),
        ) 
Example #4
Source File: local.py    From Galaxy_Plugin_Bethesda with MIT License 6 votes vote down vote up
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 
Example #5
Source File: installation.py    From blogger-cli with MIT License 6 votes vote down vote up
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),
        ) 
Example #6
Source File: get_blogger.py    From blogger-cli with MIT License 6 votes vote down vote up
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),
        ) 
Example #7
Source File: vmrun.py    From mech with MIT License 6 votes vote down vote up
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() 
Example #8
Source File: utilities.py    From Grabber with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #9
Source File: mapiex.py    From nsf2x with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #10
Source File: utils.py    From stata_kernel with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #11
Source File: store_env_in_registry.py    From coala with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #12
Source File: QgsFmvInstaller.py    From QGISFMV with GNU General Public License v3.0 5 votes vote down vote up
def WinSoftwareInstalled(hive, flag):
    aReg = winreg.ConnectRegistry(None, hive)
    aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
                          0, winreg.KEY_READ | flag)

    count_subkey = winreg.QueryInfoKey(aKey)[0]

    software_list = []

    for i in range(count_subkey):
        software = {}
        try:
            asubkey_name = winreg.EnumKey(aKey, i)
            asubkey = winreg.OpenKey(aKey, asubkey_name)
            software['name'] = winreg.QueryValueEx(asubkey, "DisplayName")[0]

            try:
                software['version'] = winreg.QueryValueEx(asubkey, "DisplayVersion")[0]
            except EnvironmentError:
                software['version'] = 'undefined'
            try:
                software['publisher'] = winreg.QueryValueEx(asubkey, "Publisher")[0]
            except EnvironmentError:
                software['publisher'] = 'undefined'
            software_list.append(software)
        except EnvironmentError:
            continue

    return software_list 
Example #13
Source File: tzwin.py    From jx-sqlite with Mozilla Public License 2.0 5 votes vote down vote up
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() 
Example #14
Source File: tzwin.py    From jx-sqlite with Mozilla Public License 2.0 5 votes vote down vote up
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 
Example #15
Source File: tzwin.py    From jx-sqlite with Mozilla Public License 2.0 5 votes vote down vote up
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] 
Example #16
Source File: tzwin.py    From jx-sqlite with Mozilla Public License 2.0 5 votes vote down vote up
def __init__(self):

        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

        tzlocalkey = winreg.OpenKey(handle, TZLOCALKEYNAME)
        keydict = valuestodict(tzlocalkey)
        tzlocalkey.Close()

        self._stdname = keydict["StandardName"].encode("iso-8859-1")
        self._dstname = keydict["DaylightName"].encode("iso-8859-1")

        try:
            tzkey = winreg.OpenKey(handle, "%s\%s"%(TZKEYNAME, self._stdname))
            _keydict = valuestodict(tzkey)
            self._display = _keydict["Display"]
            tzkey.Close()
        except OSError:
            self._display = None

        handle.Close()
        
        self._stdoffset = -keydict["Bias"]-keydict["StandardBias"]
        self._dstoffset = self._stdoffset-keydict["DaylightBias"]


        # See http://ww_winreg.jsiinc.com/SUBA/tip0300/rh0398.htm
        tup = struct.unpack("=8h", keydict["StandardStart"])

        (self._stdmonth,
         self._stddayofweek,  # Sunday = 0
         self._stdweeknumber, # Last = 5
         self._stdhour,
         self._stdminute) = tup[1:6]

        tup = struct.unpack("=8h", keydict["DaylightStart"])

        (self._dstmonth,
         self._dstdayofweek,  # Sunday = 0
         self._dstweeknumber, # Last = 5
         self._dsthour,
         self._dstminute) = tup[1:6] 
Example #17
Source File: local.py    From Galaxy_Plugin_Bethesda with MIT License 5 votes vote down vote up
def client_clientgame_path(self):
        try:
            reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
            with winreg.OpenKey(reg, BETTY_WINREG_LOCATION) as key:
                path = winreg.QueryValueEx(key, "installLocation")[0]
            return os.path.join(path, "clientgame.dat")
        except OSError:
            return ""
        except Exception as e:
            log.exception(f"Exception while retrieving clientgame path assuming none {repr(e)}")
            return "" 
Example #18
Source File: store_env_in_registry.py    From coala-bears with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #19
Source File: svg2pdf.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _inkscape_default(self):
        if sys.platform == "darwin":
            if os.path.isfile(INKSCAPE_APP):
                return INKSCAPE_APP
        if sys.platform == "win32":
            wr_handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
            try:
                rkey = winreg.OpenKey(wr_handle, "SOFTWARE\\Classes\\inkscape.svg\\DefaultIcon")
                inkscape = winreg.QueryValueEx(rkey, "")[0]
            except FileNotFoundError:
                raise FileNotFoundError("Inkscape executable not found")
            return inkscape
        return "inkscape" 
Example #20
Source File: get_blogger.py    From blogger-cli with MIT License 5 votes vote down vote up
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 
Example #21
Source File: installation.py    From blogger-cli with MIT License 5 votes vote down vote up
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 
Example #22
Source File: testbuild.py    From ce_tools with MIT License 5 votes vote down vote up
def check_installed_vs_versions():
    """
    Query the registry to find installed VS versions. Assumes that C++ support has been installed.
    Throws an exception if the expected version of VS is not present.
    :return: None
    """
    import winreg

    # Open the Visual Studio registry key.
    reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    vskey = winreg.OpenKey(reg, r'SOFTWARE\Microsoft\VisualStudio')

    subkeys = []

    # Read all the subkeys
    try:
        i = 0
        while True:
            subkeys.append(winreg.EnumKey(vskey, i))
            i += 1
    except OSError:
        pass

    # If a subkey includes '.0' it's almost certainly a version number. I've yet to see one without that.
    available_versions = [version for version in subkeys if '.0' in version]

    if args.vcversion not in available_versions:
        raise OSError('Visual Studio version {} is not installed (available: {}).'.format(args.vcversion,
                                                                                          available_versions)) 
Example #23
Source File: release_ce_project.py    From ce_tools with MIT License 5 votes vote down vote up
def get_windows_reg_value(Key, Name = ""):
    """
    WINDOWS ONLY
    Non-Recursive.
    Gets registry key(s) from windows hive
    IF Name is specified, return will contain max 1 item
    IF Name is left unspecified, return will be ALL name/value pairs in this Key.
    """
    values = {}
    
    if platform.system() != 'Windows':
        raise OSError("Can only use get_windows_reg_value() on windows platform!")
        return values
    
    import winreg
    reg = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
    ce_key = winreg.OpenKey(reg, Key)

    # The first value of the key is a null entry, so check for this.
    try:
        i = 0
        while True:
            kn, kv, kt = winreg.EnumValue(ce_key, i)
            
            if Name == kn:
                values = {kn: kv}
                break
            elif not Name:
                values[kn] = kv
            
            i += 1
    except OSError:
        pass
    
    return values 
Example #24
Source File: local_games.py    From galaxy_blizzard_plugin with MIT License 5 votes vote down vote up
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 
Example #25
Source File: get-poetry.py    From poetry with MIT License 5 votes vote down vote up
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 
Example #26
Source File: nt.py    From async_dns with MIT License 5 votes vote down vote up
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 
Example #27
Source File: win_sec_check.py    From marsnake with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #28
Source File: tzwin.py    From nzb-subliminal with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #29
Source File: tzwin.py    From nzb-subliminal with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #30
Source File: tzwin.py    From nzb-subliminal with GNU General Public License v3.0 5 votes vote down vote up
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]