@echo OFF&PUSHD %~DP0 &TITLE 绿化卸载
mode 40,23
reg query "HKU\S-1-5-19">NUL 2>&1||powershell -Command "Start-Process '%~sdpnx0' -Verb RunAs"&&EXIT
reg query "HKLM\Hardware\Description\System\CentralProcessor\0" /v "Identifier" | find /i "x86" 1>nul && set arch=x86|| set arch=x64
if not exist "!IDMan!" (
if %arch%==x64 set "IDMan=%ProgramFiles(x86)%\Internet Download Manager\IDMan.exe"
if %arch%==x86 set "IDMan=%ProgramFiles%\Internet Download Manager\IDMan.exe"
)

if "%arch%"=="x86" (
set "CLSID=HKCU\Software\Classes\CLSID"
set "HKLM=HKLM\Software\Internet Download Manager"
set "_tok=5"
) else (
set "CLSID=HKCU\Software\Classes\Wow6432Node\CLSID"
set "HKLM=HKLM\SOFTWARE\Wow6432Node\Internet Download Manager"
set "_tok=6"
)
set "nul=>nul 2>&1"
set regdata=%SystemRoot%\Temp\regdata.txt
set "idmcheck=tasklist /fi "imagename eq idman.exe" | find /i "idman.exe" >nul"

:Menu
@ echo.
@ echo.　　　　　    菜 单 选 项
@ echo.========================================
@ echo. 
@ echo.  [1] 绿化
@ echo. 
@ echo.  [2] 卸载
@ echo.
@ echo.  [3] 备份
@ echo. 
set /p zero=请输入选择项目序号（1，2，3）：
if /i "%zero%"=="1" goto Setup
if /i "%zero%"=="2" goto Uninst
if /i "%zero%"=="3" goto Backup
echo.
echo 选择无效，请重新输入！！！
timeout /t 2 >nul
cls
goto Menu

:Setup
:: Windows All
reg add "HKCU\Software\DownloadManager" /v "ToolbarStyle" /t REG_SZ /d "Small outlined" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "LaunchOnStart" /t REG_DWORD /d "0" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "FName" /t REG_SZ /d "IDM" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "LName" /t REG_SZ /d " " /f %nul%
reg add "HKCU\Software\DownloadManager" /v "Email" /t REG_SZ /d "admin@osssr.com" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "LstCheck" /t REG_SZ /d "09/09/99" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "TipStartUp" /t REG_DWORD /d "1" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "NewConnType" /t REG_DWORD /d "3" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "MaxConnectionsNumber" /t REG_DWORD /d "32" /f %nul%
reg add "HKCU\SOFTWARE\DownloadManager\DwnlPanel" /v "M4S" /t REG_DWORD /d "1" /f %nul%
reg add "HKCU\SOFTWARE\DownloadManager\DwnlPanel" /v "XS" /t REG_DWORD /d "1" /f %nul%
reg add "HKCU\SOFTWARE\DownloadManager\FoldersTree" /v "AFD" /t REG_DWORD /d "1" /f %nul%
reg add "HKCU\SOFTWARE\DownloadManager\FoldersTree" /v "Visiblity" /t REG_DWORD /d "0" /f %nul%
reg add "HKCU\Software\DownloadManager" /v "ToolbarState_v5.11" /t REG_BINARY /d "15800000168000001780000018800000198000001a8000001b8000001e800000ee840000ef840000f2800000" /f %nul%
reg add "HKCU\SOFTWARE\DownloadManager" /v "Extensions" /t REG_SZ /d "3GP 7Z AAC ACE AIF APK ARJ ASF AVI BIN BZ2 EXE GZ GZIP IMG ISO LZH M4A M4V MKV MOV MP3 MP4 MPA MPE MPEG MPG MSI MSU OGG OGV PDF PLJ PPS PPT QT R0* R1* RA RAR RM RMVB SEA SIT SITX TAR TIF TIFF WAV WMA WMV Z ZIP MSP XZ" /f %nul%

:: Windows 64-Bit
If %arch%==x64 regsvr32 /s /u IDMIECC64.dll
If %arch%==x64 regsvr32 /s /u IDMGetAll64.dll
If %arch%==x64 regsvr32 /s /u downlWithIDM64.dll

:: Windows 7/8/10
If Exist "%Public%" idmBroker.exe -RegServer

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

:: Windows 7/8/10
If Exist "%Public%" Uninstall.exe -instdriv

:: Windows 7/8/10
If Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultInstall 128 .\idmwfp.inf

:: Windows 7/8/10
If Exist "%Public%" Net Start IDMWFP >NUL 2>NUL

:LNK
powershell -NoProfile -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut($([Environment]::GetFolderPath('Desktop')) + '\Internet Download Manager.lnk'); $s.TargetPath = '%~dp0IDMan.exe'; $s.WorkingDirectory = '%~dp0'; $s.Save()"
ECHO.&ECHO.绿化完成,可直接关掉本窗口!!
ECHO.&ECHO.出现弹窗警告请先执行卸载!!!&echo.&choice /n /c YN /m "是否查看最新更新 [Y,N]?" & if errorlevel 2 echo. & set /a i+=1 &exit /b
explorer "https://www.osssr.com/657.html"&exit /b

:Uninst
cls&echo.&echo.&echo.&echo.&echo.&echo.     建议关闭浏览器及相关程序再卸载&echo.&echo.             按任意键继续…&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo                        By OSSSR.COM&pause >nul
%IDMCHECK% && taskkill /F /IM IDMan.exe /T %nul%
taskkill /F /IM "IEMonitor.exe" /T %nul%
taskkill /F /IM "IDMMsgHost.exe" /T %nul%
taskkill /F /IM "MediumILStart.exe" /T %nul%
taskkill /F /IM "IDMIntegrator64.exe" /T %nul%

If Exist "%Public%" Net Stop IDMWFP %nul%
If Not Exist "%Public%" Net Stop IDMTDI %nul%
If Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultUninstall 128 .\idmwfp.inf %nul%
If Not Exist "%Public%" Rundll32 setupapi.dll,InstallHinfSection DefaultUninstall 128 .\idmtdi.inf %nul%
If Exist "%WinDir%\SysWOW64" Regsvr32 /s /u IDMShellExt64.dll %nul%

reg delete "%HKLM%" /f %nul%
reg delete "HKCU\Software\DownloadManager" /f %nul%
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Internet Download Manager" /f %nul%
reg delete "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Internet Download Manager" /f %nul%
del /f/q "%USERPROFILE%\Desktop\Internet Download Manager.lnk" %nul%
rd /s/q "%ProgramData%\IDM" %nul%
rd /s/q "%AppData%\IDM" %nul%
rd /s/q "%AppData%\DMCache" %nul%
rd /s/q "%Temp%\IDM_Setup_Temp" %nul%
taskkill /F /IM explorer.exe >nul 2>nul &start explorer.exe

:action
reg query %CLSID% > %regdata%

for /f %%a in (%regdata%) do (
for /f "tokens=%_tok% delims=\" %%# in ("%%a") do (
echo %%#|findstr /r /i "{.*-.*-.*-.*-.*}" >nul && (set "reg=%%a"&call :scan_key)
)
)

:scan_key
reg query %reg% 2>nul | find /i "LocalServer32 InProcServer32 InProcHandler32"
reg query %reg% 2>nul | find /i "H" 1>nul || (
reg delete "%reg%" /f
) %nul%
if %errorlevel% neq 1 (
    reg delete "%reg%" /f %nul%
    if %errorlevel% equ 0 (
        call:action
    )
)

for /f "skip=2 tokens=*" %%a in ('reg query %reg% /ve 2^>nul') do echo %%a|findstr /r "[^0-9]" >nul || (
reg delete "%reg%" /f
)

for /f "skip=2 tokens=3" %%a in ('reg query %reg%\Version /ve 2^>nul') do echo %%a|findstr /r "[^0-9]" >nul || (
reg delete "%reg%" /f
)

for /f "skip=2 tokens=1" %%a in ('reg query %reg% 2^>nul') do echo %%a|findstr /r "MData Model scansk Therad" >nul && (
reg delete "%reg%" /f
)

for /f "skip=2 tokens=*" %%a in ('reg query %reg% /ve 2^>nul') do echo %%a|findstr /r "+" >nul && (
reg delete "%reg%" /f
)
CLS
ECHO.&ECHO.卸载完成, 请手动删除目录！
timeout /t 3 >NUL&EXIT

:Backup
reg delete "HKCU\Software\DownloadManager" "/v" "Email" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "Serial" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "scansk" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "tvfrdt" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "radxcnt" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "LstCheck" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "ptrk_scdt" /f %nul%
reg delete "HKCU\Software\DownloadManager" "/v" "LastCheckQU" /f %nul%
SET DS="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
FOR /F "tokens=2,*" %%I IN ('REG QUERY %DS% /v Desktop 2^>NUL^|FIND /I "Desktop"') DO SET "MYDesktop=%%~J"
reg export "HKCU\Software\DownloadManager" "%MYDesktop%\IDM备份.reg" /y %nul%
IF %ERRORLEVEL%==0 (
ECHO.&ECHO 数据保存至桌面：IDM备份.reg
) ELSE (
ECHO.&ECHO 备份失败
)

echo.&echo 按任意键返回&pause >nul & cls & goto Menu