@ECHO OFF&PUSHD %~DP0 &TITLE 绿化卸载

>NUL 2>&1 REG.exe query "HKU\S-1-5-19" || (
    ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\GetAdmin.vbs"
    ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\GetAdmin.vbs"
    "%TEMP%\GetAdmin.vbs"
    DEL /f /q "%TEMP%\GetAdmin.vbs" 2>NUL
    Exit /b
)

:Menu
echo.&echo 1.绿化
echo.&echo 2.卸载
echo.
set /p a=输入数字或字符回车：
IF NOT "%a%"=="" SET a=%a:~0,1%
if "%a%"=="1" Goto Setup
if "%a%"=="2" Goto Uninst
echo.&echo 输入无效，请重新输入！
PAUSE >NUL && CLS && GOTO MENU

:Setup
taskkill /f /im IDM* >NUL 2>NUL
taskkill /f /im IEMon* >NUL 2>NUL

reg delete "HKLM\SOFTWARE\Internet Download Manager" /f>NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wow6432Node\Internet Download Manager" /f>NUL 2>NUL

::导入注册信息
reg add "HKCU\SOFTWARE\DownloadManager" /f /v "FName" /t REG_SZ /d "Tonec" >NUL
reg add "HKCU\SOFTWARE\DownloadManager" /f /v "LName" /t REG_SZ /d "Inc." >NUL
reg add "HKCU\SOFTWARE\DownloadManager" /f /v "Email" /t REG_SZ /d "info@tonec.com" >NUL
reg add "HKCU\SOFTWARE\DownloadManager" /f /v "Serial" /t REG_SZ /d "GIRBW-HW5OD-KEKAQ-4DGNF" >NUL

:: Windows All
reg add "HKCU\Software\DownloadManager" /f /v idmvers >NUL
reg add "HKCU\Software\DownloadManager" /f /v ToolbarStyle /d "H3M Glossy" >NUL
reg add "HKCU\Software\DownloadManager" /f /v TipStartUp /t REG_DWORD /d 1 >NUL
reg add "HKCU\Software\DownloadManager" /f /v LaunchOnStart /t REG_DWORD /d 0 >NUL
reg add "HKCU\Software\DownloadManager" /f /v startImmediately /t REG_DWORD /d 0 >NUL
reg add "HKCU\Software\DownloadManager" /f /v FSSettingsChecked /t REG_DWORD /d 1 >NUL
reg add "HKCU\Software\DownloadManager\FoldersTree" /f /v AFD /t REG_DWORD /d 1 >NUL

Start /Wait /B "" "%~dp0IDMan.exe" /rtr /setlngid 2052 /fulllngfile idm_chn2.lng

:: Windows NT6
If Exist "%Public%" idmBroker.exe -RegServer
If Exist "%Public%" Uninstall.exe -instdriv

If Exist "%Public%" Net Start IDMWFP >NUL 2>NUL
If Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultInstall 128 .\idmwfp.inf

:: Windows NT
If Not Exist "%Public%" Net Start idmtdi >NUL 2>NUL
If Not Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultInstall 128 .\idmtdi.inf

::创建桌面快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Internet Download Manager.lnk""):b.TargetPath=""%~dp0IDMan.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
ECHO.&ECHO 绿化完成，按任意键返回！&PAUSE >NUL 2>NUL & CLS & GOTO MENU

:Uninst
taskkill /f /im IDM* >NUL 2>NUL
taskkill /f /im IEMon* >NUL 2>NUL

regsvr32 /s /u idmfsa.dll downlWithIDM.dll
regsvr32 /s /u IDMIECC.dll IDMGetAll.dll IDMShellExt.dll
If Exist "%WinDir%\SysWOW64" regsvr32 /s /u IDMIECC64.dll
If Exist "%WinDir%\SysWOW64" regsvr32 /s /u downlWithIDM64.dll
If Exist "%WinDir%\SysWOW64" regsvr32 /s /u IDMGetAll64.dll
If Exist "%WinDir%\SysWOW64" regsvr32 /s /u IDMShellExt64.dll

If Exist "%Public%" idmBroker.exe -unRegServer
If Exist "%Public%" Uninstall.exe -uninstdriv

If Exist "%Public%" Net Stop IDMWFP >NUL 2>NUL
If Not Exist "%Public%" Net Stop IDMTDI >NUL 2>NUL

If Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultUninstall 128 .\idmwfp.inf
If Not Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultUninstall 128 .\idmtdi.inf

rd/s/q "%AppData%\IDM" 2>NUL
rd/s/q "%ProgramData%\IDM" 2>NUL
rd/s/q "%AllUsersProfile%\Application Data\IDM" 2>NUL

reg delete "HKLM\SOFTWARE\Internet Download Manager" /f>NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wow6432Node\Internet Download Manager" /f>NUL 2>NUL

taskkill /f /im explorer.exe >NUL 2>NUL & start explorer
reg delete "HKCU\Software\DownloadManager" /f>NUL 2>NUL
ECHO.&ECHO 卸载完成（重启电脑才能删除目录），按任意键返回！&PAUSE >NUL 2>NUL & CLS & GOTO MENU