def close(self):      
      """ Close file and write in registry """
      from win32con import REG_SZ, REG_BINARY
      from win32api import RegSetValueEx
      
      # If the file has been opened correctly
      if self.handle != None and self.data != None:
         # If the file has not been deleted
         if self.deleted == 0:
            # If the file is opened with binary mode
            if self.binary:
               typ = REG_BINARY
            else:
               typ = REG_SZ
            
            # Write data in registry base
            RegSetValueEx (self.handle, "", 0, typ, self.data.getvalue())
         
         # Close file
         result = self.data.close()
         self.data = None
         return result
 Close file and write in registry 
recipes/Python/163969_Win32_registry_file/recipe-163969.py