@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 WSHelper* >NUL 2>NUL
taskkill /f /im PDFExpert* >NUL 2>NUL
taskkill /f /im PDFelement* >NUL 2>NUL

::清除万兴PDF专家软件相关残留文件
rd/s/q "%ProgramData%\PDF Expert" 2>NUL
rd/s/q "%AppData%\Wondershare\PDFExpert" 2>NUL
reg delete "HKLM\SOFTWARE\PDF Expert" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wondershare\5387" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wondershare\5239" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wondershare\PDFExpert" /f >NUL 2>NUL

::预设简体中文、关闭自动检测更新（已预设调目录下的PDFExpert.ini）

::软件的相关注册表键值
reg add "HKCR\wspe8" /f /ve /d "万兴PDF专家" >NUL 2>NUL
reg add "HKCR\wspe8" /f /v "URL Protocol" /d "" >NUL 2>NUL
reg add "HKCR\wspe8\shell\open\command" /f /ve /d "\"%~dp0PDFExpert.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCU\Software\Wondershare\PDFExpert" /f /v "Version" /d "8.0.6.222" >NUL 2>NUL
reg add "HKCU\Software\Wondershare\PDFExpert" /f /v "InstallPath" /d "%~dp0\" >NUL 2>NUL
reg add "HKCU\Software\Wondershare\PDFExpert" /f /v "InstallName" /d "%~dp0PDFExpert.exe" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\PDFExpert" /f /v "Version" /d "8.0.6.222" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\PDFExpert" /f /v "InstallPath" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\PDFExpert" /f /v "InstallName" /d "%~dp0PDFExpert.exe" >NUL 2>NUL
reg add "HKLM\Software\PEPrinter\Wondershare PDFelement Monitor" /f /v "InstallName" /d "%~dp0PDFExpert.exe" >NUL 2>NUL

::本地OCR组件检测释放识别标记(默认会释放到C盘程序目录)
::reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C72325EC-BF56-412B-8899-43B663F69A4F}_is1" /f /v "UninstallString" /d "%~dp0\"

::创建桌面快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\万兴PDF专家.lnk""):b.TargetPath=""%~sdp0PDFExpert.exe"":b.WorkingDirectory=""%~sdp0"":b.Save:close")

:MENU
CLS&ECHO.&ECHO 完成, 以下自选：
ECHO 1、关联为PDF文档默认程序
ECHO 2、添加PDF文档右键菜单项
ECHO 3、安装万兴PDF专家打印机
CHOICE /C 123 /N  >NUL 2>NUL
IF "%ERRORLEVEL%"=="3" GOTO Addmonport
IF "%ERRORLEVEL%"=="2" GOTO AddMenuExt
IF "%ERRORLEVEL%"=="1" GOTO Associate

:Associate
::/？帮助 /A 关联文件, /D 取消关联, /C 清除关联
FileAssociation.exe /a .pdf "%~dp0PDFExpert.exe" "%~dp0projectfile.ico" >NUL 2>NUL
ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&GOTO MENU

:AddMenuExt
reg add "HKCR\.fdf\OpenWithList\PDFExpert.exe" /f /ve /d "" >NUL 2>NUL
reg add "HKCR\.pdf\OpenWithList\PDFExpert.exe" /f /ve /d "" >NUL 2>NUL
reg add "HKCR\Applications\PDFExpert.exe\Shell\Open\Command" /f /ve /d "\"%~dp0PDFExpert.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\SystemFileAssociations\.pdf\Shell\WondersharePDFExpert" /f /ve /d "用万兴PDF编辑"  >NUL 2>NUL
reg add "HKCR\SystemFileAssociations\.pdf\Shell\WondersharePDFExpert\Command" /f /ve /d  "\"%~dp0PDFExpert.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\WondersharePDF.Document8\DefaultIcon" /f /ve /d "\"%~dp0projectfile.ico\""  >NUL 2>NUL
reg add "HKCR\WondersharePDF.Document8\shell\open\command" /f /ve /d "\"%~dp0PDFExpert.exe\" \"%%1\""  >NUL 2>NUL
ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&GOTO MENU

:Addmonport
echo f|copy /y "PECRT32.dll" "%WinDir%\SysWOW64\" >NUL 2>NUL
echo f|copy /y "WSPrtSetup\PEExpertPrinterMonitor.dll" "%WinDir%\System32\" >NUL 2>NUL
start /b /min /wait "" "%~dp0WSPrtSetup\WSPrtSetup.exe" /dvrname "Wondershare PDF Expert" /prtname "Wondershare PDF Expert" /monname "Wondershare PDF Expert Monitor" /monport "Wondershare PDF Expert Monitor Port" /monfile "%~dp0WSPrtSetup\PEExpertPrinterMonitor.dll" >NUL 2>NUL
start /wait PrinterRepairTool.exe >NUL 2>NUL
ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&GOTO MENU