@ECHO OFF & CD /D %~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
)

taskkill /f /im Thunder* >NUL 2>NUL
taskkill /f /im XLLiveUD* >NUL 2>NUL
taskkill /f /im xlbrowsershell*  >NUL 2>NUL
taskkill /f /im DownloadSDKServer* >NUL 2>NUL

rd/s/q "%tmp%\Xmp"2>NUL
rd/s/q "%tmp%\Xunlei"2>NUL
rd/s/q "%tmp%\Thunder"2>NUL
rd/s/q "%tmp%\XLLiveUD"2>NUL
rd/s/q "%tmp%\ThunderLiveUD"2>NUL
rd/s/q "%tmp%\Thunder Network"2>NUL
rd/s/q "%AppData%\迅雷" 2>NUL
rd/s/q "%AppData%\迅雷X" 2>NUL
rd/s/q "%AppData%\thunderx"2>NUL
rd/s/q "%AppData%\thunderx"2>NUL
rd/s/q "%AppData%\Thunder Network"2>NUL
del "%AllUsersProfile%\Application Data\APlayerCodecs3.exe" >NUL 2>NUL
del/f/q "%AppData%\Microsoft\Windows\Libraries\迅雷下载.library-ms" >NUL 2>NUL
rd/s/q "%ProgramData%\Thunder Network"2>NUL
rd/s/q "%AllUsersProfile%\Xunlei"2>NUL
rd/s/q "%AllUsersProfile%\Thunder Network"2>NUL
rd/s/q "%AllUsersProfile%\Application Data\Xunlei"2>NUL
rd/s/q "%AllUsersProfile%\Application Data\Thunder Network"2>NUL
rd/s/q "%CommonProgramFiles%\Thunder Network"2>NUL
rd/s/q "%CommonProgramFiles(x86)%\Thunder Network"2>NUL
rd/s/q "%UserProfile%\Local Settings\Application Data\Thunder Network"2>NUL
rd/s/q "%UserProfile%\Local Settings\Application Data\Pusher"2>NUL
rd/s/q "%UserProfile%\My Documents\Thunder"2>NUL
rd/s/q "%UserProfile%\AppData\Roaming\迅雷" 2>NUL
rd/s/q "%UserProfile%\AppData\Roaming\迅雷X" 2>NUL
rd/s/q "%UserProfile%\AppData\Roaming\thunderx"2>NUL
rd/s/q "%UserProfile%\AppData\Roaming\XLGameBox"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\XunLei"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\XunleiBHO"2>NUL
rd/s/q "%UserProfile%\AppData\LocalLow\Thunder Network"2>NUL
rd/s/q "%AllUsersProfile%\Application Data\Thunder Network"2>NUL
If exist "%PUBLIC%" rd/s/q "%PUBLIC%\Thunder Network"2>NUL
If exist "%PUBLIC%" rd/s/q "%PUBLIC%\Documents\Thunder Network"2>NUL
If exist "%PUBLIC%" md  "%PUBLIC%\Thunder Network\cid_store.dat" 2>NUL
If exist "%PUBLIC%" md  "%PUBLIC%\Thunder Network\tp_common_info.dat" 2>NUL
If exist "%PUBLIC%" md  "%PUBLIC%\Thunder Network\emule_upload_list.dat" 2>NUL
If not exist "%PUBLIC%" md "%AllUsersProfile%\Application Data\Thunder Network\cid_store.dat" 2>NUL
If not exist "%PUBLIC%" md "%AllUsersProfile%\Application Data\Thunder Network\tp_common_info.dat" 2>NUL
If not exist "%PUBLIC%" md "%AllUsersProfile%\Application Data\Thunder Network\emule_upload_list.dat" 2>NUL

regsvr32 /s BHO\ThunderAgent.dll
regsvr32 /s BHO\ThunderAgent64.dll
regsvr32 /s BHO\Platform\np_tdieplat.dll

reg add "HKCR\.xltd" /f /ve /d "Xunlei.TDFile.6" >NUL 2>NUL
reg add "HKCR\.downlist" /f /ve /d "Xunlei.LSTFile.6" >NUL 2>NUL
reg add "HKCR\.torrent" /f /ve /d "Xunlei.Bittorrent.6" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\Shell\Open" /f /ve /d "使用迅雷下载未完成文件" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\Shell\Open" /f /ve /d "使用迅雷下载该BT文件" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\Shell\Open" /f /ve /d "使用迅雷下载该任务列表文件" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\DefaultIcon" /f /ve /d "%~dp0Program\TorrentFile.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\DefaultIcon" /f /ve /d "%~dp0Program\XLDownloadList.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.Bittorrent.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\DefaultIcon" /f /ve /d "%~dp0Program\XLTempFile.ico" >NUL 2>NUL
reg add "HKCR\Xunlei.TDFile.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\Xunlei.LSTFile.6\Shell\Open\command" /f /ve /d "\"%~dp0Program\Thunder.exe\" \"%%1\"" >NUL 2>NUL

reg add "HKCU\Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下载" /f /ve /d "%~dp0BHO\geturl.htm"  >NUL 2>NUL
reg add "HKCU\Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下载" /f /v "Contexts" /t reg_DWORD /d "0x00000022"  >NUL 2>NUL
reg add "HKCU\Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下载全部链接" /f /ve /d "%~dp0BHO\getAllurl.htm" >NUL 2>NUL
reg add "HKCU\Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下载全部链接" /f /v "Contexts" /t reg_DWORD /d "0x000000f3" >NUL 2>NUL

reg delete "HKCU\Software\MozillaPlugins\@xunlei.com" /f >NUL 2>NUL
reg delete "HKLM\Software\MozillaPlugins\@xunlei.com" /f >NUL 2>NUL
reg delete "HKCU\Software\Google\Chrome\NativeMessagingHosts" /f >NUL 2>NUL
reg delete "HKLM\Software\Google\Chrome\NativeMessagingHosts" /f >NUL 2>NUL
reg delete "HKLM\Software\Wow6432Node\MozillaPlugins\@xunlei.com" /f >NUL 2>NUL
reg delete "HKLM\Software\Wow6432Node\Google\Chrome\NativeMessagingHosts" /f >NUL 2>NUL
reg add "HKLM\Software\Google\Chrome\NativeMessagingHosts\com.xunlei.thunder" /f /ve /d "%~dp0BHO\com.xunlei.thunder.json" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\Software\MozillaPlugins\@xunlei.com/npxunlei;version=1.0.0.2"  /f  /v path /d "%~dp0BHO\npxunlei.dll" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\Software\Wow6432Node\MozillaPlugins\@xunlei.com/npxunlei;version=1.0.0.2" /f  /v path /d "%~dp0BHO\npxunlei.dll" >NUL 2>NUL

if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\Software\Thunder Network\ThunderOem\thunder_backwnd"  /f /v dir /d "%~dp0"  >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\Software\Thunder Network\ThunderOem\thunder_backwnd"  /f /v instdir /d "%~dp0"  >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\Software\Thunder Network\ThunderOem\thunder_backwnd"  /f /v Path /d "%~dp0Program\Thunder.exe"  >NUL 2>NUL 
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\Software\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v dir /d "%~dp0"  >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\Software\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v instdir /d "%~dp0"  >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\Software\Wow6432Node\Thunder Network\ThunderOem\thunder_backwnd" /f /v Path /d "%~dp0Program\Thunder.exe"  >NUL 2>NUL

echo set WshShell = WScript.CreateObject("WScript.Shell")>tmp.vbs
echo set oShellLink = WshShell.CreateShortcut("%~dp0" ^& "\Thunder.lnk")>>tmp.vbs
echo oShellLink.TargetPath ="%~dp0Program\Thunder.exe">>tmp.vbs
echo oShellLink.WindowStyle ="1">>tmp.vbs
echo oShellLink.IconLocation = "%~dp0Program\Thunder.exe">>tmp.vbs
echo oShellLink.Description = "">>tmp.vbs
echo oShellLink.WorkingDirectory = "%~dp0">>tmp.vbs
echo oShellLink.Save>>tmp.vbs
call tmp.vbs & del  tmp.vbs >NUL 2>NUL

ECHO.&ECHO 绿化完成！创建快捷方式？
ECHO.&ECHO 是敲任意键，否直接关闭！&PAUSE >NUL 2>NUL
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\迅雷X.lnk""):b.TargetPath=""%~dp0Program\Thunder.exe"":b.WorkingDirectory=""%~dp0Program\"":b.Save:close")
CLS &ECHO.&ECHO 完成！&PAUSE >NUL 2>NUL & EXIT