@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 YunDetectSer* >NUL 2>NUL
taskkill /f /im BaiduNetdisk* /t >NUL 2>NUL

::移除相关残留文件
rd/s/q "%TEMP%\baidu" 2>NUL
rd/s/q "%TEMP%\bdyunguanjiaskinres" 2>NUL
rd/s/q "%AppData%\BaiduYunKernel" 2>NUL
rd/s/q "%AppData%\BaiduYunGuanjia" 2>NUL
rd/s/q "%AppData%\Baidu\BaiduNetdisk" 2>NUL
rd/s/q "%AppData%\Baidu\BaiduYunKernel" 2>NUL 


::移除此电脑里百度网盘快捷方式及BT种子关联项
reg delete "HKLM\SOFTWARE\Classes\Baiduyunguanjia" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\BaiduYunGuanjia.torrent" /f >NUL 2>NUL
reg delete "HKCR\CLSID\{679F137C-3162-45da-BE3C-2F9C3D093F64}" /f >NUL 2>NUL
reg delete "HKCR\CLSID\{18701C81-34AB-498E-8C7F-5D26B9C36732}" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\CLSID\{679F137C-3162-45da-BE3C-2F9C3D093F64}" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\CLSID\{18701C81-34AB-498E-8C7F-5D26B9C36732}" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{679F137C-3162-45da-BE3C-2F9C3D093F64}" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{18701C81-34AB-498E-8C7F-5D26B9C36732}" /f >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\Classes\CLSID\{679F137C-3162-45da-BE3C-2F9C3D093F64}" /f >NUL 2>NUL
reg delete "HKU\%SID%\SOFTWARE\Classes\CLSID\{18701C81-34AB-498E-8C7F-5D26B9C36732}" /f >NUL 2>NUL
reg delete "HKU\%SID%\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{679F137C-3162-45da-BE3C-2F9C3D093F64}" /f >NUL 2>NUL
reg delete "HKU\%SID%\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{18701C81-34AB-498E-8C7F-5D26B9C36732}" /f >NUL 2>NUL
reg delete "HKU\%SID%\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /f /v "{18701C81-34AB-498E-8C7F-5D26B9C36732}" >NUL 2>NUL

ECHO.&ECHO 正在阻止后台偷偷上传
echo y|icacls "Autoupdate" /c /grant "Everyone:(R,RX)" /inheritance:r >NUL 2>NUL
echo y|icacls "kernel.dll" /c /grant "Everyone:(R,RX)" /inheritance:r >NUL 2>NUL
echo y|icacls "module\KernelCom" /c /grant "Everyone:(R,RX)" /inheritance:r >NUL 2>NUL
if exist BaiduNetdiskHost.exe ren BaiduNetdiskHost.exe BaiduNetdiskHost.bak >NUL 2>NUL
::BaiduNetdiskRender.exe（精简该程序会导致第三方登陆页面无法加载，PDF文档无法用内置阅读器打开）
::if exist BaiduNetdiskRender.exe ren BaiduNetdiskRender.exe BaiduNetdiskRender.bak >NUL 2>NUL

::软件路径检测标记
reg add "HKCU\Software\Baidu\BaiduYunGuanjia" /f /v "installDir" /d "%~dp0\" >NUL 2>NUL
IF NOT EXIST "%ProgramW6432%" (
reg add "HKLM\SOFTWARE\Baidu\BaiduYunGuanjia" /f /v "installDir" /d "%~dp0\" >NUL 2>NUL ) ELSE (
reg add "HKLM\SOFTWARE\Baidu\BaiduYunGuanjia" /f /v "installDir" /d "%~dp0\" /reg:32 >NUL 2>NUL)

ECHO.&ECHO 正在关联浏览器调用项
regsvr32 /s npYunWebDetect.dll
if exist YunDetectService.exe start YunDetectService.exe reg

ECHO.&ECHO 正在创建桌面快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\百度网盘.lnk""):b.TargetPath=""%~sdp0BaiduNetdisk.exe"":b.WorkingDirectory=""%~sdp0"":b.Save:close")

:MENU
CLS&ECHO.&ECHO 完成, 以下选项自选：
ECHO.&ECHO 1、启用视频播放程序(会驻留进程)
ECHO.&ECHO 2、注册微软OFFICE软件工具栏的加载项
ECHO.&ECHO 3、添加资源管理器右键上传百度网盘项

CHOICE /C 123 /N >NUL 2>NUL
IF "%ERRORLEVEL%"=="3" GOTO AddShellExt
IF "%ERRORLEVEL%"=="2" GOTO AddRender
IF "%ERRORLEVEL%"=="1" GOTO AddHostEXE

:AddHostEXE
if exist BaiduNetdiskHost.bak ren BaiduNetdiskHost.bak BaiduNetdiskHost.exe >NUL 2>NUL
CLS&ECHO.&ECHO 完成! &TIMEOUT /t 2 >NUL&GOTO MENU

:AddRender
IF NOT EXIST "%ProgramW6432%" (
regsvr32 /s YunOfficeAddin.dll
) ELSE (
regsvr32 /s YunOfficeAddin.dll
regsvr32 /s YunOfficeAddin64.dll
)
CLS&ECHO.&ECHO 完成! &TIMEOUT /t 2 >NUL&GOTO MENU

:AddShellExt
IF NOT EXIST "%ProgramW6432%" (
regsvr32 /s YunShellExtV1.dll
) ELSE (
regsvr32 /s YunShellExtV164.dll
)
CLS&ECHO.&ECHO 完成! &TIMEOUT /t 2 >NUL&GOTO MENU