import os import subprocess # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_install(dir, args): import re import _winreg import time import os fromURL=['https://patchportal.one.comodo.com/portal/packages/spm/OpenVPN/x86/TAP-Windows_9.21.2.cer', 'https://patchportal.one.comodo.com/portal/packages/spm/Clavister OneConnect SSL VPN/x86/tap-windows-9.21.2.exe'] ## Here mention the download url ## ## print fromURL ##import os ##if not os.path.exists(dir): ## os.makedirs(dir) import ctypes 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) import subprocess with disable_file_system_redirection(): import urllib Down_path=os.environ['TEMP'] for i in range(0,len(fromURL)): #print (fromURL[i]) fileName = fromURL[i].split('/')[-1] DownTo = os.path.join(Down_path, fileName) def downloadFile(DownTo, fromURL): try: with open(DownTo, 'wb') as f: f.write(urllib.urlopen(fromURL).read()) if os.path.isfile(DownTo): return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000) except: return 'Please Check URL or Download Path!' if __name__=='__main__': downloadFile(DownTo, fromURL[i] ) ## ## print Down_path import shutil try: shutil.copy2(DownTo, dir) ## print("%s is copied to %s"%(DownTo, dir)) ## print "File copied successfully" except Exception as err : print err fp=fromURL[i].split('/')[-1] filename=fp #Give the certificate name with extension ## print filename import os import subprocess if filename.endswith(".cer"): ## print"cer" os.chdir(Down_path) #cmd=os.popen("") cmd=os.path.join(dir,filename) cmd1='certutil -addstore "TrustedPublisher" '+fp ## print(cmd1) ## process= subprocess.Popen(cmd1,shell=True, stdout=subprocess.PIPE) ## result=process.communicate() ## print (result) process= subprocess.Popen(cmd1,shell=True, stdout=subprocess.PIPE) result=process.communicate() ## print(result) ## ret=process.returncode ## ## ## if ret==0: ## print filename+"success" ## print filename+" is installed to trusted root certificate succesfully" ## ## ## else: ## print filename+"not" ## print filename+" is not installed to trusted root certificate" elif filename.endswith(".exe"): ## print (os.getcwd()) ## print "exe" cmd12=filename+" /S" tap_install=os.popen(filename+" /S").read() ## print (tap_install) else: pass os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_uninstall(dir, args): os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode' # dir: string -> directory where installer exist # args: string -> which includes all parameters with space delimiter def spm_update(dir, args): os.chdir(dir) argslist = args.split() try: subprocess.check_call(argslist) print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'