import ctypes
import re
import time
import socket
import _winreg
import platform
import shutil
import ssl
import urllib2
import getpass
import zipfile
import shutil
import os
path_shortcut="C:\ProgramData\extraction_file"			
if os.path.exists("C:\\Program Files (x86)"):
    URL=r"https://docs.google.com/uc?export=download&id=1szATg1C9rKLsmEKw-dM-aDef6RE36HfJ" #provide a URL of package
else:
    URL=r"https://docs.google.com/uc?export=download&id=1Lq9TxsMC7X_DmOCWDNRxwmbItqwQpxKE"

from subprocess import Popen,PIPE
start=time.time()
def Download(src_path, URL,fp):
    import urllib2
    request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
    try:
        gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
        parsed = urllib2.urlopen(request,context=gcontext)
    except:
        parsed = urllib2.urlopen(request)
    if not os.path.exists(src_path):
        os.makedirs(src_path)
    with open(fp, 'wb') as f:
        while True:
            chunk=parsed.read(100*1000*1000)
            if chunk:
                f.write(chunk)
            else:
                break
    return fp
Folder=os.environ['programdata']+r"\extraction_file"
if not os.path.exists(Folder):
    os.mkdir(Folder)
fileName=r"mbam.exe"
src_path=Folder
fp = os.path.join(src_path, fileName)    
Excutable_path=Download(Folder, URL,fp)
print "Downloaded succesfully to "+Excutable_path+""
#dest_path="C:\ProgramData\extraction_file"
os.chdir("C:\ProgramData\extraction_file")
if os.path.exists("C:\\Program Files (x86)"):
    process=Popen("""mbam.exe /DIR="C:\Program Files (x86)\Malwarebytes Anti-Exploit" /SP- /VERYSILENT /SUPPRESSMSGBOXES """,stdout=PIPE,stderr=PIPE)
    r,e=process.communicate()
    if e:
        print e
    else:
        print "Successfully Installed"
        print r
else:
    process=Popen("""mbam.exe /DIR="C:\Program Files\Malwarebytes Anti-Exploit" /SP- /VERYSILENT /SUPPRESSMSGBOXES """,stdout=PIPE,stderr=PIPE)
    r,e=process.communicate()
    if e:
        print e
    else:
        print "Successfully Installed"
        print r
