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 os.chdir(dir) argslist = args.split() fromURL='https://patchportal.one.comodo.com/portal/packages/spm/OpenVPN/x86/TAP-Windows_9.24.2.cer'## Here mention the download url ##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['PROGRAMDATA'] fileName = fromURL.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 ) 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.split('/')[-1] filename=fp #Give the certificate name with extension import os import subprocess cmd=os.path.join(dir,filename) cmd1='certutil -addstore "TrustedPublisher" '+fp process= subprocess.Popen(cmd1,shell=True, stdout=subprocess.PIPE) result=process.communicate() #process1= subprocess.Popen(trust_publisher,shell=True, stdout=subprocess.PIPE) ## result=process.communicate() ## ret=process.returncode ## ## if ret==0: ## print filename+" is installed to trusted root certificate succesfully" ## ## else: ## print filename+" is not installed to trusted root certificate" 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): import re import _winreg import time import os import subprocess os.chdir(dir) argslist = args.split() try: unarglist2='"C:\Program Files\OpenVPN\Uninstall.exe" /S' subprocess.check_call(unarglist2) print "Open VPN " +'older Version are removed' time.sleep(30) except subprocess.CalledProcessError as e: print "Open VPN " +'older Version does not exist, uninstaller returncode:' + str(e.returncode); ## print ("copying and installing trusted certificates") fromURL='https://patchportal.one.comodo.com/portal/packages/spm/OpenVPN/x86/TAP-Windows_9.24.2.cer'## Here mention the download url print fromURL 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['PROGRAMDATA'] fileName = fromURL.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 ) 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.split('/')[-1] filename=fp #Give the certificate name with extension import os import subprocess cmd=os.path.join(dir,filename) cmd1='certutil -addstore "TrustedPublisher" '+fp print "Installing publisher" process= subprocess.Popen(cmd1,shell=True, stdout=subprocess.PIPE) try: os.popen("Taskkill /IM tap-windows.exe /F").read() except: pass time.sleep(10) result=process.communicate() print "Publisher installed" ## process1= subprocess.Popen(trust_publisher,shell=True, stdout=subprocess.PIPE) ## result=process.communicate() ## ret=process.returncode ## ## ## if ret==0: ## print filename+" is installed to trusted root certificate succesfully" ## ## ## else: ## print filename+" is not installed to trusted root certificate" try: subprocess.check_call(argslist) #subprocess.check_call(args) try: os.popen('Taskkill /IM tap-windows.exe /F').read() os.popen('Taskkill /IM tapinstall.exe /F').read() except: pass print 'retcode' + str(0) + 'retcode' except subprocess.CalledProcessError as e: print 'retcode' + str(e.returncode) + 'retcode'