@echo off
rem 切换至BAT文件所在目录
cd /d "%~dp0"
echo %cd%
echo.

rem 检查小工具完整性
cd SeeyonActivexInstall
if not exist IE.reg goto ErrorNO1
if not exist RunAsAdmin.ini goto ErrorNO1
if not exist RunAsAdmin_x64.exe goto ErrorNO1
if not exist RunAsAdmin_x86.exe goto ErrorNO1
if not exist SeeyonActivexInstall.bat goto ErrorNO1
if not exist SeeyonActivexInstall.dll goto ErrorNO1
if not exist url.txt goto ErrorNO1

rem 获取url.txt第一行内容给变量urlStr
set /p urlStr=<"%~dp0SeeyonActivexInstall\url.txt"
echo urlStr -^> %urlStr%

if "%urlStr:~0,8%"=="http://[" goto doForIPv6
if "%urlStr:~0,9%"=="https://[" goto doForIPv6
goto doForIPv4

:doInstall
rem 执行控件安装
IF "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (RunAsAdmin_x64.exe -AddIeReg %tHost2%) ELSE (RunAsAdmin_x86.exe -AddIeReg %tHost2%)

goto ThisEnds

:ThisEnds
rem echo 安装结束，请重新打开IE浏览器访问。
rem echo.
rem echo 请按任意键退出. . . & pause >nul
exit

:ErrorNO1
echo 请解压 "SeeyonActivexInstall" 目录与 "INSTALL.BAT" 文件，再进行控件安装。
echo.
echo 请按任意键退出. . . & pause >nul
exit



:doForIPv4
rem http://172.20.2.20:80/seeyon/index.jsp
rem https://172.20.2.20:80/seeyon/index.jsp
rem 获取主机字符串
for /f "usebackq tokens=2 delims=:" %%i in (`echo %urlStr%`) do (
  set tHost1=%%i
)
echo tHost1 -^> %tHost1%
for /f "usebackq tokens=1 delims=/" %%i in (`echo %tHost1%`) do (
  set tHost2=%%i
)
echo tHost2 -^> %tHost2%
echo.
goto doInstall



:doForIPv6
rem http://[fe80::8cbe:2a29:59a7:d950]:88/seeyon/main.do
rem https://[fe80::8cbe:2a29:59a7:d950]:88/seeyon/main.do
rem 获取主机字符串
for /f "usebackq tokens=2 delims=[" %%i in (`echo %urlStr%`) do (
  set tHost1=%%i
)
echo tHost1 -^> %tHost1%
for /f "usebackq tokens=1 delims=]" %%i in (`echo %tHost1%`) do (
  set tHost2=%%i
)
echo tHost2 -^> %tHost2%
echo.
goto doInstall
