TrackingPrevention_options = 3 #edit here
"""
give 0 in the TrackingPrevention_options if you want to set the TrackingPrevention to "disable"
give 1 in the TrackingPrevention_options if you want to set the TrackingPrevention to "Basic"
give 2 in the TrackingPrevention_options if you want to set the TrackingPrevention to "Balanced"
give 3 in the TrackingPrevention_options if you want to set the TrackingPrevention to "Strict"
"""
EnhanceSecurityMode_options = 2 #edit here
"""
give 0 in the EnhanceSecurityMode_options if you want to set the "Enhance your security on the web" to "disable"
give 1 in the EnhanceSecurityMode_options if you want to set the "Enhance your security on the web" to "Balanced"
give 2 in the EnhanceSecurityMode_options if you want to set the "Enhance your security on the web" to "Strict"
"""
MD_SmartScreen_options = 1 #edit here
"""
give 0 in the MD_SmartScreen_options if you want disable "Microsoft Defender SmartScreen"
give 1 in the MD_SmartScreen_options if you want to enable "Microsoft Defender SmartScreen"
"""
BlockPotentiallyUnwantedApps_options = 1 #edit here
"""
give 0 in the BlockPotentiallyUnwantedApps_options if you want disable "block potentially unwanted apps"
give 1 in the BlockPotentiallyUnwantedApps_options if you want to enable "block potentially unwanted apps"
"""
WebsiteTypoProtection_options = 1 #edit here
"""
give 0 in the WebsiteTypoProtection_options if you want disable "Website typo protection"
give 1 in the WebsiteTypoProtection_options if you want to enable "Website typo protection"
"""
SiteSafetyServices_options = 1 #edit here
"""
give 0 in the SiteSafetyServices_options if you want to Turn off site safety services to get more info about the sites you visit
give 1 in the SiteSafetyServices_options if you want to Turn on site safety services to get more info about the sites you visit
"""
Scareware_Blocker_options = 1 #edit here
"""
give 0 in the Scareware_Blocker_options if you want to disable "Scareware Blocker"
give 1 in the Scareware_Blocker_options if you want to enable "Scareware Blocker"
"""

import os
from subprocess import PIPE, Popen
import ctypes
import re

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 ecmd(command):   
    from subprocess import Popen, PIPE
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
        out, err = obj.communicate()
        return out,err
            
print(ecmd('REG ADD HKLM\Software\Policies\Microsoft\Edge /v TrackingPrevention /t REG_DWORD /d %s /f'%(TrackingPrevention_options)))
print(ecmd('REG ADD HKLM\Software\Policies\Microsoft\Edge /v EnhanceSecurityMode /t REG_DWORD /d %s /f'%(EnhanceSecurityMode_options)))
print(ecmd('REG ADD HKLM\Software\Policies\Microsoft\Edge /v TyposquattingCheckerEnabled /t REG_DWORD /d %s /f'%(WebsiteTypoProtection_options)))
print(ecmd('REG ADD HKLM\Software\Policies\Microsoft\Edge /v SiteSafetyServicesEnabled /t REG_DWORD /d %s /f'%(SiteSafetyServices_options)))
print(ecmd('REG ADD HKLM\Software\Policies\Microsoft\Edge /v ScarewareBlockerProtectionEnabled /t REG_DWORD /d %s /f'%(Scareware_Blocker_options)))

with disable_file_system_redirection():
    users=os.popen("net users").read().split()[5:-4]
    fil_users=[i.strip() for i in users if i.strip()!="Administrator" and i.strip()!="DefaultAccount" and i.strip()!="Guest" and i.strip()!="WDAGUtilityAccount"]
    userout = os.popen('query user').read()
    curusername = re.findall("(.*)Active",userout)[0].split()[0]
    curcheck = list(filter(lambda x: x.lower()==curusername.lower(),fil_users))
    if curcheck:
        try:
            sid = os.popen("wmic useraccount where name=\"%s\" get sid"%(curusername)).read().splitlines()[1].strip()
            print(ecmd('REG ADD "HKEY_USERS\%s\Software\Microsoft\Edge\SmartScreenEnabled" /v "" /t REG_DWORD /d %s /f'%(sid,MD_SmartScreen_options)))
            print(ecmd('REG ADD "HKEY_USERS\%s\Software\Microsoft\Edge\SmartScreenPuaEnabled" /v "" /t REG_DWORD /d %s /f'%(sid,BlockPotentiallyUnwantedApps_options)))
        except Exception as err:
            print(err)
        else:
            fil_users.remove(curcheck[0])
    for i in fil_users:
        if os.path.exists("C:\\Users\\%s\\ntuser.dat"%(i)):
            out,err = ecmd("reg load HKU\\%s C:\\Users\\%s\\ntuser.dat"%(i,i))
            if out:
                try:
                    print(ecmd('REG ADD "HKEY_USERS\%s\Software\Microsoft\Edge\SmartScreenEnabled" /v "" /t REG_DWORD /d %s /f'%(i,MD_SmartScreen_options)))
                    print(ecmd('REG ADD "HKEY_USERS\%s\Software\Microsoft\Edge\SmartScreenPuaEnabled" /v "" /t REG_DWORD /d %s /f'%(i,BlockPotentiallyUnwantedApps_options)))
                except Exception as err:
                    print(err)
                else:
                    unLoad = os.popen("reg unload HKU\\%s"%(i)).read()
            else:
                print(err)
