@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 PDFelement* >NUL 2>NUL

::清除万兴产品附加垃圾组件及开机启动项 WSHelper；
rd/s/q "%LocalAppData%\Wondershare\WSHelper" 2>NUL
rd/s/q "%AppData%\Wondershare\Wondershare Helper Compact" 2>NUL
IF NOT EXIST "%ProgramW6432%" (
rd/s/q "%CommonProgramFiles%\Wondershare\Wondershare Helper Compact"2>NUL
) ELSE (
rd/s/q "%CommonProgramW6432%\Wondershare\Wondershare Helper Compact"2>NUL
rd/s/q "%CommonProgramFiles(x86)%\Wondershare\Wondershare Helper Compact"2>NUL)
reg delete "HKCU\Software\Wondershare\Wondershare Helper Compact" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wondershare\Wondershare Helper Compact" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\WOW6432Node\Wondershare\Wondershare Helper Compact" /f >NUL 2>NUL
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /f /v "Wondershare Studio" >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v "Wondershare Helper Compact.exe" >NUL 2>NUL
reg delete "HKCU\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /f /v "WSVCUUpdateHelper.exe" >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v "WSVCUUpdateHelper.exe" >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v "Wondershare Helper Compact.exe" >NUL 2>NUL
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /f /v "Wondershare Helper Compact.exe" >NUL 2>NUL

::清除万兴PDF专家软件相关残留文件
rd/s/q "%ProgramData%\PDF Expert" 2>NUL
rd/s/q "%ProgramData%\PDFelement 7" 2>NUL
rd/s/q "%AppData%\Wondershare\PDF Expert" 2>NUL
rd/s/q "%AppData%\Wondershare\PDFelement 7"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\WOW6432Node\Wondershare\5387" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\WOW6432Node\Wondershare\5239" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wondershare\Wondershare PDFelement 7" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wow6432Node\Wondershare\Wondershare PDF Expert" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Wow6432Node\Wondershare\Wondershare PDFelement 7" /f >NUL 2>NUL

::阻止升级提示及强制下载安装包(dll也已修改)
del/f/q "%Temp%\pdfelement_*.exe" >NUL 2>NUL
del/f/q "%Temp%\WhatsNewFile*.xml" >NUL 2>NUL
del/f/q "%Temp%\FullUpdateConfig*.xml" >NUL 2>NUL
del/f/q "%Temp%\PatchUpdateConfig*.xml" >NUL 2>NUL
md "%temp%\WhatsNewFile_万兴PDF专家.xml" 2>NUL
md "%temp%\FullUpdateConfig_万兴PDF专家.xml" 2>NUL
md "%temp%\PatchUpdateConfig_万兴PDF专家.xml" 2>NUL
attrib +r +a +s +h +x "%temp%\WhatsNewFile_万兴PDF专家.xml" >NUL 2>NUL
attrib +r +a +s +h +x "%temp%\FullUpdateConfig_万兴PDF专家.xml" >NUL 2>NUL
attrib +r +a +s +h +x "%temp%\PatchUpdateConfig_万兴PDF专家.xml" >NUL 2>NUL

::软件相关注册表键值
reg add "HKCR\wspe7" /f /v "URL Protocol" /d "" >NUL 2>NUL
reg add "HKCR\wspe7" /f /ve /d "Wondershare PDFelement" >NUL 2>NUL
reg add "HKCR\wspe7\shell\open\command" /f /ve /d "\"%~dp0PDFelement.exe\" \"%%1\"" >NUL 2>NUL
IF NOT EXIST "%ProgramW6432%" (
echo f|copy /y "TWAINDSM\32\WSPECRT.dll" "%WinDir%\System32\" >NUL 2>NUL
echo f|copy /y "TWAINDSM\32\TWAINDSM.dll" "%WinDir%\System32\" >NUL 2>NUL
echo f|copy /y "TWAINDSM\32\TWAINDSM32.msm" "%WinDir%\System32\" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\Wondershare PDFelement 7" /f /v "InstallPath" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\Wondershare PDFelement 7" /f /v "appsetuppath" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\Software\Wondershare\Wondershare PDFelement 7" /f /v "RegAppVersion" /d "7.6.8.5031" >NUL 2>NUL
reg add "HKLM\Software\PEPrinter\Wondershare PDFelement Monitor" /f /v "InstallName" /d "%~dp0PDFelement.exe" >NUL 2>NUL
) ELSE (
echo f|copy /y "TWAINDSM\32\WSPECRT.dll" "%WinDir%\SysWOW64\" >NUL 2>NUL
echo f|copy /y "TWAINDSM\32\TWAINDSM.dll" "%WinDir%\SysWOW64\" >NUL 2>NUL
echo f|copy /y "TWAINDSM\32\TWAINDSM32.msm" "%WinDir%\SysWOW64\" >NUL 2>NUL
reg add "HKLM\Software\Wow6432Node\Wondershare\Wondershare PDFelement 7" /f /v "InstallPath" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\Software\Wow6432Node\Wondershare\Wondershare PDFelement 7" /f /v "appsetuppath" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\Software\Wow6432Node\Wondershare\Wondershare PDFelement 7" /f /v "RegAppVersion" /d "7.6.8.5031" >NUL 2>NUL
reg add "HKLM\Software\Wow6432Node\PEPrinter\Wondershare PDFelement Monitor" /f /v "InstallName" /d "%~dp0PDFelement.exe" >NUL 2>NUL
)
::解决依赖的.NET的WCF构建症状问题
if exist FixServiceModel30Reg.js cscript FixServiceModel30Reg.js >NUL 2>NUL
::安装万兴PDF专家打印机
start /b /wait "" "%~dp0CreatorForPDFEditor\WSPrtSetup.exe" /dvrname "Wondershare PDFelement" /prtname "Wondershare PDFelement" /monname "Wondershare PDFelement Monitor" /monport "Wondershare PDFelement Port" /monfile "%~dp0CreatorForPDFEditor\WSPDFelementMonitor.dll" >NUL 2>NUL
start /wait PrinterRepaireTool.exe >NUL 2>NUL

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

:MENU
CLS&ECHO.&ECHO 完成, 以下自选：
ECHO.&ECHO 1、设置为PDF默认程序
ECHO.&ECHO 2、添加PDF右键菜单项
CHOICE /C 12 /N  >NUL 2>NUL
IF "%ERRORLEVEL%"=="2" GOTO AddMenuExt
IF "%ERRORLEVEL%"=="1" GOTO Associate

:Associate
FileAssociation.exe /InstallFileAssociate >NUL 2>NUL
ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&GOTO MENU

:AddMenuExt
reg add "HKCR\.fdf\OpenWithList\PDFelement.exe" /f /ve /d "" >NUL 2>NUL
reg add "HKCR\.pdf\OpenWithList\PDFelement.exe" /f /ve /d "" >NUL 2>NUL
reg add "HKCR\Applications\PDFelement.exe\Shell\Open\Command" /f /ve /d "\"%~dp0PDFelement.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  "\"%~dp0PDFelement.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCR\WondersharePDF.Document7\DefaultIcon" /f /ve /d "\"%~dp0projectfile.ico\""  >NUL 2>NUL
reg add "HKCR\WondersharePDF.Document7\shell\open\command" /f /ve /d "\"%~dp0PDFelement.exe\" \"%%1\""  >NUL 2>NUL
start /b /min /wait "" PEAddInDeployment.exe >NUL 2>NUL
ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&GOTO MENU