@chcp 936 >nul
@echo off

title 卸载好压绿色版
set "installpath=%~dp0"
set SafeCenterPath=

:chkadm
pushd "%~dp0"
reg query "HKU\S-1-5-19" >nul 2>nul || ( start "" mshta vbscript:createobject^("shell.application"^).shellexecute^("cmd.exe","/C pushd ""%~dp0"" && ""%~f0""","","runas",1^)^(window.close^) && exit )

:confirm
echo.
echo 按任意键继续卸载，或者直接关闭窗口退出
pause > nul
cls

:uninstall
echo.
echo ☆☆☆☆正在卸载...
echo 停止程序进程
taskkill /f /im HaoZip.exe >nul 2>nul
taskkill /f /im HaoZipSvc.exe >nul 2>nul
taskkill /f /im Helper_Haozip.exe >nul 2>nul
taskkill /f /im HaozipAssistant.exe >nul 2>nul

echo 卸载HaoZipExt.dll组件
if exist HaoZipExt64.dll regsvr32 /s /u HaoZipExt64.dll
if exist HaoZipExt.dll regsvr32 /s /u HaoZipExt.dll
if exist HaoZipExt32.dll regsvr32 /s /u HaoZipExt32.dll
reg delete "HKCU\SOFTWARE\2345.com\HaoZip" /f >nul 2>nul
reg delete "HKCU\SOFTWARE\2345.com\Haozip_2345Upgrade" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\HaoZip" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\HaoZip" /f >nul 2>nul
rd /s/q "%AppData%\HaoZip\Application" 2>nul

echo 卸载相关服务
net stop HaoZipSvc >nul 2>nul
sc delete HaoZipSvc >nul 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\HaoZipSvc" /f >nul 2>nul
reg delete "HKLM\SYSTEM\ControlSet001\Services\HaoZipSvc" /f >nul 2>nul

net stop 2345HaoZip >nul 2>nul
sc delete 2345HaoZip >nul 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\2345HaoZip" /f >nul 2>nul
reg delete "HKLM\SYSTEM\ControlSet001\Services\2345HaoZip" /f >nul 2>nul

net stop HaozipVirtualCDBus >nul 2>nul
sc delete HaozipVirtualCDBus >nul 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\HaozipVirtualCDBus" /f >nul 2>nul
reg delete "HKLM\SYSTEM\ControlSet001\Services\HaozipVirtualCDBus" /f >nul 2>nul

echo 卸载虚拟光驱
if exist HaoZipCD.exe ( 
  "%installpath%HaoZipCD.exe" quit
  "%installpath%HaoZipCD.exe" ud -am
  "%installpath%HaoZipCD.exe" nr
)

echo 执行HaoZipLoader.exe卸载
if exist HaoZipLoader.exe ( 
  "%installpath%HaoZipLoader.exe" -preUninstall
  "%installpath%HaoZipLoader.exe" -uninstall
  "%installpath%HaoZipLoader.exe" -uninstallsafecenter
)

echo 清除注册配置信息
reg delete "HKCU\SOFTWARE\2345.com\HaoZip" /f >nul 2>nul
reg delete "HKCU\SOFTWARE\2345.com\Haozip_2345Upgrade" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\HaoZip" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\HaoZip" /f >nul 2>nul

reg delete "HKLM\SOFTWARE\RegisteredApplications" /v "HaoZip" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\RegisteredApplications" /v "HaoZip" /f >nul 2>nul

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\HaoZip.exe" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\HaoZip.exe" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\HaoZipC.exe" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\HaoZipC.exe" /f >nul 2>nul

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\HaoZip" /f >nul 2>nul

reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" /v "{5FED836A-C96C-4d88-A91E-F63F07726585}" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved" /v "{5FED836A-C96C-4d88-A91E-F63F07726585}" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\CLSID\{5FED836A-C96C-4d88-A91E-F63F07726585}" /f >nul 2>nul
reg delete "HKLM\SOFTWARE\Classes\WOW6432Node\CLSID\{5FED836A-C96C-4d88-A91E-F63F07726585}" /f >nul 2>nul

rd /s/q "%TEMP%\HaoZip" 2>nul
rd /s/q "%AppData%\HaoZip" 2>nul
rd /s/q "%AppData%\Helper_2345" 2>nul
rd /s/q "%AppData%\2345DomainMon" 2>nul

rd /s/q "%AppData%\Microsoft\Windows\Start Menu\Programs\好压" 2>nul
rd /s/q "%ProgramData%\Microsoft\Windows\Start Menu\Programs\好压" 2>nul
del /f/q "%Public%\Desktop\好压.lnk" 2>nul
del /f/q "%UserProfile%\Desktop\好压.lnk" 2>nul

schtasks /delete /tn "Haozip_2345Upgrade Task" /f >nul 2>nul
echo ☆☆☆☆卸载完成
echo.
echo 提示：若想删除程序文件，请在重启电脑或重启explorer后，删除该文件夹："%installpath%"

for /f "tokens=1,2,* " %%i in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\2345SafeCenter /v UninstallString 2^>nul ^| find /i "UninstallString"') do (set "SafeCenterPath=%%k")
if not "%SafeCenterPath%" == "" if exist "%SafeCenterPath%" (
  rem appwiz.cpl
  echo.
  echo 提示：建议在系统设置或者控制面板中，手动卸载“安全组件 - 2345”。
  goto out
)

for /f "tokens=1,2,* " %%i in ('reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\2345SafeCenter /v UninstallString 2^>nul ^| find /i "UninstallString"') do (set "SafeCenterPath=%%k")
if not "%SafeCenterPath%" == "" if exist "%SafeCenterPath%" (
  rem appwiz.cpl
  echo.
  echo 提示：建议在系统设置或者控制面板中，手动卸载“安全组件 - 2345”。
)

:out
echo.
echo 按任意键退出
timeout /t 50 >nul 2>nul || ( 
  pause > nul
)
exit

