@ECHO OFF&(PUSHD "%~DP0")&(REG QUERY "HKU\S-1-5-19">NUL 2>&1)||(
powershell -Command "Start-Process '%~sdpnx0' -Verb RunAs"&&EXIT)

::结束软件相关进程
taskkill /F /IM "IDM*" /T >NUL 2>NUL
taskkill /F /IM "IDMGrHlp.exe" >NUL 2>NUL
taskkill /F /IM "IEMonitor.exe" >NUL 2>NUL
taskkill /F /IM "IDMMsgHost.exe" >NUL 2>NUL
taskkill /F /IM "MediumILStart.exe" >NUL 2>NUL
taskkill /F /IM "MediumILStart.exe" >NUL 2>NUL
taskkill /F /IM "IDMIntegrator64.exe" >NUL 2>NUL

::清除注册信息及开机启动项
ECHO.&ECHO 请稍等片刻，正在安装
reg delete "HKLM\Software\DownloadManager" /f >NUL 2>NUL
reg delete "HKLM\Software\Download Manager" /f >NUL 2>NUL
reg delete "HKLM\Software\DownloadManager" /f /reg:32 >NUL 2>NUL
reg delete "HKLM\Software\Download Manager" /f /reg:32 >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Internet Download Manager" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Internet Download Manager" /f /reg:32 >NUL 2>NUL
reg delete "HKU\.DEFAULT\Software\DownloadManager" /f >NUL 2>NUL
reg delete "HKU\.DEFAULT\Software\Download Manager" /f >NUL 2>NUL
reg delete "HKU\.DEFAULT\Software\DownloadManager" /f /reg:32 >NUL 2>NUL
reg delete "HKU\.DEFAULT\Software\Download Manager" /f /reg:32 >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "MData" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "LName" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "FName" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "Email" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "Serial" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "scansk" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "tvfrdt" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "radxcnt" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "LstCheck" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "ptrk_scdt" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "LastCheckQU" >NUL 2>NUL
reg delete "HKCU\Software\DownloadManager" /f /v "CheckUpdtVM" >NUL 2>NUL
for /f "delims=" %%a in ('wmic userAccount where "Name='%userName%'" get SID /value') do call set "%%a" >NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "MData" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "LName" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "FName" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "Email" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "Serial" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "scansk" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "tvfrdt" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "radxcnt" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "LstCheck" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "ptrk_scdt" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "LastCheckQU" >NUL 2>NUL
reg delete "HKU\%SID%\Software\DownloadManager" /f /v "CheckUpdtVM" >NUL 2>NUL
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /f /v "IDMan" >NUL 2>NUL
reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /f /v "IDMan" >NUL 2>NUL
reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /f /v "IDMan" /reg:32 >NUL 2>NUL
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{84797876-C678-1780-A556-0CD06786780F}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\Wow6432Node\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul

reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{84797876-C678-1780-A556-0CD06786780F}" /f >Nul 2>Nul
reg delete "HKEY_CURRENT_USER\Software\Classes\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul

reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{84797876-C678-1780-A556-0CD06786780F}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul

reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{5312C54E-A385-46B7-B200-ABAF81B03935}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{436D67E1-2FB3-4A6C-B3CD-FF8A41B0664D}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{84797876-C678-1780-A556-0CD06786780F}" /f >Nul 2>Nul
reg delete "HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul

reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\Software\Classes\Wow6432Node\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{7B8E9164-324D-4A2E-A46D-0165FB2000EC}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{6DDF00DB-1234-46EC-8356-27E7B2051192}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{D5B91409-A8CA-4973-9A0B-59F713D25671}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{5ED60779-4DE2-4E07-B862-974CA4FF2E9C}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{07999AC3-058B-40BF-984F-69EB1E554CA7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{E8CF4E59-B7A3-41F2-86C7-82B03334F22A}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{9C9D53D4-A978-43FC-93E2-1C21B529E6D7}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{79873CC5-3951-43ED-BDF9-D8759474B6FD}" /f >Nul 2>Nul
reg delete "HKEY_USERS\.DEFAULT\SOFTWARE\WOW6432Node\Classes\CLSID\{E6871B76-C3C8-44DD-B947-ABFFE144860D}" /f >Nul 2>Nul

::执行注册机，算法自动生成序列号
Rundll32.exe "%~dp0KGIDM.dll" GEN
::添加用户名注册信息检测依赖标记
IF NOT EXIST "%ProgramW6432%" (
reg add "HKLM\Software\Internet Download Manager" /f /v "FName" /d "Tonec" >NUL 2>NUL
reg add "HKLM\Software\Internet Download Manager" /f /v "LName" /d "Inc." >NUL 2>NUL
reg add "HKLM\Software\Internet Download Manager" /f /v "Email" /d "info@tonec.com" >NUL 2>NUL
::reg add "HKLM\Software\Internet Download Manager" /f /v "Serial" /d "AV6L9-VPYMI-06HZY-E4D8Y" >NUL 2>NUL
::reg add "HKLM\SOFTWARE\Internet Download Manager" /f /v "AdvIntDriverEnabled2" /t REG_DWORD /d "1" >NUL 2>NUL
) ELSE (
reg add "HKLM\Software\Internet Download Manager" /f /v "FName" /d "Tonec" /reg:32 >NUL 2>NUL
reg add "HKLM\Software\Internet Download Manager" /f /v "LName" /d "Inc." /reg:32 >NUL 2>NUL
reg add "HKLM\Software\Internet Download Manager" /f /v "Email" /d "info@tonec.com" /reg:32 >NUL 2>NUL
::reg add "HKLM\Software\Internet Download Manager" /f /v "Serial" /d "AV6L9-VPYMI-06HZY-E4D8Y" /reg:32 >NUL 2>NUL
::reg add "HKLM\SOFTWARE\Internet Download Manager" /f /v "AdvIntDriverEnabled2" /t REG_DWORD /d "1" /reg:32 >NUL 2>NUL
)

::调优选项:启用简体中文,启用额外主题,取消开机启动,取消启动提示弹窗, 添加其它格式支持；
reg add "HKCU\Software\DownloadManager" /f /v "LanguageID" /t REG_DWORD /d "2052" >NUL 2>NUL
reg add "HKCU\Software\DownloadManager" /f /v "ToolbarStyle" /d "Faenza" >NUL 2>NUL
reg add "HKCU\Software\DownloadManager" /f /v "TipStartUp" /t REG_DWORD /d "1" >NUL 2>NUL
reg add "HKCU\Software\DownloadManager" /f /v "LaunchOnStart" /t REG_DWORD /d "0" >NUL 2>NUL
reg add "HKCU\SOFTWARE\DownloadManager" /f /v "Extensions" /d "3GP 7Z AAC ACE AIF 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 ESD WIM MSP APK APKS APKM CAB MSP" >NUL 2>NUL


::调用官方参数静默安装
start "" /min /wait "%~dp0idmBroker.exe" -RegServer
start "" /min /wait "%~dp0IDMan.exe" /onsilentsetup /s /q

::删除安装过程残留文件
rd/s/q "%AppData%\IDM"2>NUL
rd /s/q "%Temp%\IDM_Setup_Temp" 2>NUL
del/f/q "%Temp%\*~DF*.TMP" >NUL 2>NUL

::创建桌面快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Internet Download Manager.lnk""):b.TargetPath=""%~sdp0IDMan.exe"":b.WorkingDirectory=""%~sdp0"":b.Save:close")

ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&EXIT