Folder_name=r"Trend_Micro_Uninstaller"                        
Folder_Path=r"C:\Users\ABC\Desktop"            # Provide Path for the Uninstaller download
URL=r'https://drive.google.com/uc?export=download&id=1OxZeiu4yDNW0505OX4OtLJQCBzGpIYN2' 
dest_path=Folder_Path+"\\"+Folder_name

import os
import subprocess        
import urllib
import ctypes
import urllib2
import zipfile

if not os.path.exists(dest_path):
    os.makedirs(dest_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)

def Download(path, URL):
    print "Download started"
    fileName ="SA_Uninstall_1384.zip"
    
    fp = os.path.join(dest_path, fileName)
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    parsed = urllib2.urlopen(request)
    if os.path.exists(dest_path):
        print "Path already exists"
    if not os.path.exists(dest_path):
        os.makedirs(dest_path)
        print "Path created"
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    print "The file downloaded successfully in specified path"
    return fp
	
def filezip(src_path,destination_path):
    with disable_file_system_redirection():
        with zipfile.ZipFile(src_path,"r") as zip_ref:
            zip_ref.extractall(destination_path)
            print 'file successfully unzipped to' + destination_path
            
def bat(path):
     with disable_file_system_redirection():
         print "Excuting Bat File"
         process = subprocess.Popen([path],stdout=subprocess.PIPE)
         stdout = process.communicate()[0]
         print "---------------------------"
         print stdout            
			
try:
    fs = Download(dest_path, URL)
    ep=os.path.join(dest_path, fs.split(os.sep)[-1][:-4])
    filezip(fs,ep)
    path = ep+"\\SA_Uninstall\\Uninstall.bat"
    bat(path)
    print "Trend Micro agent has been successfully uninstalled"
except:
    pass
