import os import subprocess import ctypes import ssl import time from urllib2 import Request, urlopen # --------------------------------------------------------- # CONFIGURATION # --------------------------------------------------------- ADOBE_CDN_URL = "https://cdn-patchportal-one.comodo.com/portal/packages/spm/Adobe%20Acrobat/x64/AcroRdrDCx642500120997_MUI.exe" INSTALL_ARGS = "/sAll /rs /rps /msi /norestart /quiet EULA_ACCEPT=YES" UNINSTALL_CMD = "MsiExec.exe /X{AC76BA86-1033-FF00-7760-BC15014EA700} /qn" # --------------------------------------------------------- # Disable WOW64 filesystem redirection # --------------------------------------------------------- class disable_file_system_redirection: _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection def __enter__(self): self.old_value = ctypes.c_long() self.success = self._disable(ctypes.byref(self.old_value)) def __exit__(self, type, value, traceback): if self.success: self._revert(self.old_value) # --------------------------------------------------------- # Execute command (waits until completion) # --------------------------------------------------------- def ecmd(cmd): with disable_file_system_redirection(): p = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) p.communicate() return p.returncode # --------------------------------------------------------- # SAFE CLEANUP (NO FORCE DELETE) # --------------------------------------------------------- def safe_cleanup(): paths = [ r"C:\Users\Public\Desktop\Adobe Acrobat DC.lnk", r"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe Acrobat DC.lnk", r"C:\Program Files\Adobe\Acrobat DC" ] for p in paths: try: if os.path.isfile(p): os.remove(p) elif os.path.isdir(p): if not os.listdir(p): # remove only if empty os.rmdir(p) except: pass # --------------------------------------------------------- # Download installer from CDN # --------------------------------------------------------- def download_installer(url, dst, retries=3): for _ in range(retries): try: req = Request(url, headers={'User-Agent': 'Mozilla/5.0'}) ctx = ssl._create_unverified_context() res = urlopen(req, context=ctx, timeout=60) with open(dst, 'wb') as f: while True: data = res.read(1024 * 1024) if not data: break f.write(data) if os.path.exists(dst) and os.path.getsize(dst) > 5 * 1024 * 1024: return True except: time.sleep(20) return False # --------------------------------------------------------- # INSTALL # --------------------------------------------------------- def spm_install(dir, args): temp = os.environ.get("TEMP", "C:\\Windows\\Temp") installer = os.path.join(temp, "AdobeAcrobatDC_x64.exe") if not download_installer(ADOBE_CDN_URL, installer): print "retcode1retcode" return rc = ecmd('"%s" %s' % (installer, INSTALL_ARGS)) print "retcode" + str(rc) + "retcode" try: os.remove(installer) except: pass # --------------------------------------------------------- # UNINSTALL # --------------------------------------------------------- def spm_uninstall(dir, args): rc = ecmd(UNINSTALL_CMD) time.sleep(20) safe_cleanup() print "retcode" + str(rc) + "retcode" # --------------------------------------------------------- # UPDATE (ORDER AS REQUESTED) # --------------------------------------------------------- def spm_update(dir, args): spm_uninstall(dir, args) time.sleep(10) safe_cleanup() spm_install(None, None)