def __init__(self, key_guid, sid=None, use_32bit=False):
        '''
        Initialise against a software item or component.

        All software has a unique "Identifer" within the registry. This can be free
        form text/numbers e.g. "MySoftware" or
        GUID e.g. "{0EAF0D8F-C9CF-4350-BD9A-07EC66929E04}"

        Args:
            key_guid (str): Identifer.
            sid (str): Security IDentifier of the User or None for Computer/Machine.
            use_32bit (bool):
                Regisrty location of the Identifer. ``True`` 32 bit registry only
                meaning fully on 64 bit OS.
        '''
        self.__reg_key_guid = key_guid  # also called IdentifyingNumber(wmic)
        self.__squid = ''
        self.__reg_products_path = ''
        self.__reg_upgradecode_path = ''
        self.__patch_list = None

        # If a valid GUID create the SQUID also.
        guid_match = self.__guid_pattern.match(key_guid)
        if guid_match is not None:
            for index in range(1, 12):
                # __guid_pattern breaks up the GUID
                self.__squid += guid_match.group(index)[::-1]

        if sid:
            # User data seems to be more spreadout within the registry.
            self.__reg_hive = 'HKEY_USERS'
            self.__reg_32bit = False  # Force to False
            self.__reg_32bit_access = 0  # HKEY_USERS does not have a 32bit and 64bit view
            self.__reg_uninstall_path = ('{0}\\Software\\Microsoft\\Windows\\'
                                         'CurrentVersion\\Uninstall\\{1}').format(sid, key_guid)
            if self.__squid:
                self.__reg_products_path = \
                    '{0}\\Software\\Classes\\Installer\\Products\\{1}'.format(sid, self.__squid)
                self.__reg_upgradecode_path = \
                    '{0}\\Software\\Microsoft\\Installer\\UpgradeCodes'.format(sid)
                self.__reg_patches_path = \
                    ('Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\'
                     '{0}\\Products\\{1}\\Patches').format(sid, self.__squid)
        else:
            self.__reg_hive = 'HKEY_LOCAL_MACHINE'
            self.__reg_32bit = use_32bit
            self.__reg_32bit_access = self.__use_32bit_lookup[use_32bit]
            self.__reg_uninstall_path = \
                'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0}'.format(key_guid)
            if self.__squid:
                self.__reg_products_path = \
                    'Software\\Classes\\Installer\\Products\\{0}'.format(self.__squid)
                self.__reg_upgradecode_path = 'Software\\Classes\\Installer\\UpgradeCodes'
                self.__reg_patches_path = \
                    ('Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\'
                     'S-1-5-18\\Products\\{0}\\Patches').format(self.__squid)

        # OpenKey is expensive, open in advance and keep it open.
        # This must exist
        try:
            # pylint: disable=no-member
            self.__reg_uninstall_handle = \
                win32api.RegOpenKeyEx(getattr(win32con, self.__reg_hive),
                                      self.__reg_uninstall_path,
                                      0,
                                      win32con.KEY_READ | self.__reg_32bit_access)
        except pywintypes.error as exc:  # pylint: disable=no-member
            if exc.winerror == winerror.ERROR_FILE_NOT_FOUND:
                log.error(
                    'Software/Component Not Found  key_guid: \'%s\', '
                    'sid: \'%s\' , use_32bit: \'%s\'',
                    key_guid, sid, use_32bit
                )
            raise  # This must exist or have no errors

        self.__reg_products_handle = None
        if self.__squid:
            try:
                # pylint: disable=no-member
                self.__reg_products_handle = \
                    win32api.RegOpenKeyEx(getattr(win32con, self.__reg_hive),
                                          self.__reg_products_path,
                                          0,
                                          win32con.KEY_READ | self.__reg_32bit_access)
            except pywintypes.error as exc:  # pylint: disable=no-member
                if exc.winerror == winerror.ERROR_FILE_NOT_FOUND:
                    log.debug(
                        'Software/Component Not Found in Products section of registry '
                        'key_guid: \'%s\', sid: \'%s\', use_32bit: \'%s\'',
                        key_guid, sid, use_32bit
                    )
                    self.__squid = None  # mark it as not a SQUID
                else:
                    raise

        self.__mod_time1970 = 0
        # pylint: disable=no-member
        mod_win_time = win32api.RegQueryInfoKeyW(self.__reg_uninstall_handle).get('LastWriteTime', None)
        # pylint: enable=no-member
        if mod_win_time:
            # at some stage __int__() was removed from pywintypes.datetime to return secs since 1970
            if hasattr(mod_win_time, 'utctimetuple'):
                self.__mod_time1970 = time.mktime(mod_win_time.utctimetuple())
            elif hasattr(mod_win_time, '__int__'):
                self.__mod_time1970 = int(mod_win_time)
def __init__ ( self , key_guid , sid = None , use_32bit = False ) : self . __reg_key_guid = key_guid self . __squid = '' self . __reg_products_path = '' self . __reg_upgradecode_path = '' self . __patch_list = None guid_match = self . __guid_pattern . match ( key_guid ) if guid_match is not None : for index in range ( 1 , 12 ) : self . __squid += guid_match . group ( index ) [ : : - 1 ] if sid : self . __reg_hive = 'HKEY_USERS' self . __reg_32bit = False self . __reg_32bit_access = 0 self . __reg_uninstall_path = ( '{0}\\Software\\Microsoft\\Windows\\' 'CurrentVersion\\Uninstall\\{1}' ) . format ( sid , key_guid ) if self . __squid : self . __reg_products_path = '{0}\\Software\\Classes\\Installer\\Products\\{1}' . format ( sid , self . __squid ) self . __reg_upgradecode_path = '{0}\\Software\\Microsoft\\Installer\\UpgradeCodes' . format ( sid ) self . __reg_patches_path = ( 'Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\' '{0}\\Products\\{1}\\Patches' ) . format ( sid , self . __squid ) else : self . __reg_hive = 'HKEY_LOCAL_MACHINE' self . __reg_32bit = use_32bit self . __reg_32bit_access = self . __use_32bit_lookup [ use_32bit ] self . __reg_uninstall_path = 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0}' . format ( key_guid ) if self . __squid : self . __reg_products_path = 'Software\\Classes\\Installer\\Products\\{0}' . format ( self . __squid ) self . __reg_upgradecode_path = 'Software\\Classes\\Installer\\UpgradeCodes' self . __reg_patches_path = ( 'Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\' 'S-1-5-18\\Products\\{0}\\Patches' ) . format ( self . __squid ) try : self . __reg_uninstall_handle = win32api . RegOpenKeyEx ( getattr ( win32con , self . __reg_hive ) , self . __reg_uninstall_path , 0 , win32con . KEY_READ | self . __reg_32bit_access ) except pywintypes . error as exc : if exc . winerror == winerror . ERROR_FILE_NOT_FOUND : log . error ( 'Software/Component Not Found  key_guid: \'%s\', ' 'sid: \'%s\' , use_32bit: \'%s\'' , key_guid , sid , use_32bit ) raise self . __reg_products_handle = None if self . __squid : try : self . __reg_products_handle = win32api . RegOpenKeyEx ( getattr ( win32con , self . __reg_hive ) , self . __reg_products_path , 0 , win32con . KEY_READ | self . __reg_32bit_access ) except pywintypes . error as exc : if exc . winerror == winerror . ERROR_FILE_NOT_FOUND : log . debug ( 'Software/Component Not Found in Products section of registry ' 'key_guid: \'%s\', sid: \'%s\', use_32bit: \'%s\'' , key_guid , sid , use_32bit ) self . __squid = None else : raise self . __mod_time1970 = 0 mod_win_time = win32api . RegQueryInfoKeyW ( self . __reg_uninstall_handle ) . get ( 'LastWriteTime' , None ) if mod_win_time : if hasattr ( mod_win_time , 'utctimetuple' ) : self . __mod_time1970 = time . mktime ( mod_win_time . utctimetuple ( ) ) elif hasattr ( mod_win_time , '__int__' ) : self . __mod_time1970 = int ( mod_win_time )
Initialise against a software item or component.

        All software has a unique "Identifer" within the registry. This can be free
        form text/numbers e.g. "MySoftware" or
        GUID e.g. "{0EAF0D8F-C9CF-4350-BD9A-07EC66929E04}"

        Args:
            key_guid (str): Identifer.
            sid (str): Security IDentifier of the User or None for Computer/Machine.
            use_32bit (bool):
                Regisrty location of the Identifer. ``True`` 32 bit registry only
                meaning fully on 64 bit OS.