NOTE:
Run as Local System User.
download_url = 'https://script-downloads.itarian.com/Globalprotect/GlobalProtect64-6.1.0.msi' ## provide your download url here
download_path = 'C:\\Windows\\Temp\Globalprotect' ## provide your path here where the file has to been downloaded
file_name = 'GlobalProtect64-6.1.0.msi' ## provide your file name with extention
import os
import subprocess
import ctypes
import urllib2
import ssl
if os.path.exists(download_path):
pass
else:
os.makedirs(download_path)
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)
with disable_file_system_redirection():
def download(fromURL,DownTo):
print('File Downloading......')
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}
context = ssl._create_unverified_context()
request = urllib2.Request(fromURL, headers=headers)
req = urllib2.urlopen(request,context=context)
try:
with open(DownTo, 'wb') as f:
while True:
chunk = req.read(100*1000*1000)
if chunk:
f.write(chunk)
else:
break
if os.path.isfile(DownTo):
print("File Downloaded...")
return "Success"
except:
return 'Please Check URL or Download Path!'
def install(cmd,path,filename):
os.chdir(path)
obj = subprocess.Popen(cmd, shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out, err = obj.communicate()
if err:
print(err)
else:
print(filename+' installed successfully...')
return "Success"
src_path = download_path+'\\'+file_name
Download = download(download_url,src_path)
if Download == "Success":
command = 'msiexec /i "'+src_path+'" /quiet PORTAL="prisma.dfpi.ca.gov"'
Install = install(command,download_path,file_name)
if Install == "Success":
pass
else:
print("Error occurred while installing...!")
else:
print("Error occurred while downloading the file...!")
Comments