@echo off
ver|findstr "5\.[0-9]\.[0-9][0-9]*" > nul && (goto init)
ver|findstr "\<6\.[0-9]\.[0-9][0-9]*\> \<10\.[0-9]\.[0-9][0-9]*\>" > nul && (goto admin)

:admin
rem 申请管理员权限
%1 %2 mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :init","","runas",1)(window.close)&goto :eof

:init
title Radmin Server v3.5.2.1 卸载程序
color 80

rem 判断64位系统和32位系统
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
	goto x86
) else (
	goto x64
)
exit

:x64
set RserverPath=%windir%\SysWOW64\rserver30
set RsetupPath=%RserverPath%\rsetup64.exe
goto Run
exit

:x86
set RserverPath=%windir%\System32\rserver30
set RsetupPath=%RserverPath%\rsetup.exe
goto Run

:Run
echo 删除服务和虚拟显卡驱动...
%RsetupPath% /stop
%RsetupPath% /intuninstall

rem 生成防火墙白名单规则兼容XP和2003系统
set FirewallDel64=netsh advfirewall firewall delete rule name="Radmin Server 3"
set FirewallDel86=netsh firewall delete allowedprogram program="%RserverPath%\rserver3.exe" profile=ALL
ver|findstr "5\.[0-9]\.[0-9][0-9]*" > nul && (set FirewallDel=%FirewallDel86%&set is32=)  
ver|findstr "\<6\.[0-9]\.[0-9][0-9]*\> \<10\.[0-9]\.[0-9][0-9]*\>" > nul && (set FirewallDel=%FirewallDel64%&set is32=/reg:32)
echo 删除防火墙规则.
%FirewallDel%

echo 删除 radmin server 的注册表配置信息.
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Radmin /f %is32%

echo 删除快捷方式
for /f "tokens=2,*" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop"') do set "desktop_dir=%%j"
del /f /q "%desktop_dir%\Radmin Server 设置.lnk"
del /f /q "%desktop_dir%\Radmin Server 卸载.lnk"

echo 卸载破解补丁并清空目录
START /B /WAIT rundll32 %RserverPath%\wsock32.dll,ntsclean
@ping 127.0.0.1 -n 3 > null
rd /s /q %RserverPath%

echo.
echo 卸载完成！请重启系统以彻底删除 Radmin Server 虚拟显卡驱动.
echo.
pause