@echo off
echo:
rem ALT+数字键2和7调出彩色文字前缀
echo =============================
echo [32m欢迎使用《OHH小工具集》Excel工具箱[0m
echo =============================
echo:
rem 检测插件运行环境
echo [34m正在检测插件运行环境...[0m
setlocal enabledelayedexpansion
set existnet=false 
for /f "tokens=7 delims=\" %%a in ('REG QUERY HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs') do (
	if not "%%a" == "Client" if not "%%a" == "Default" (
		if "%1" == "" (
			SET gg=%%a			
			SET ss=!gg:~22,6!
			SET ss=!ss:,=!
			SET ss=!ss:P=!
			rem 打印.net framework版本号
			rem echo !ss!
			if "!ss:v4.6.2=!" NEQ "!ss!" (
				set existnet=true
			)
		) else (			
			if "!%%a:v4.6.2=!" NEQ "!%%a!" (
			 	set existnet=true
			)	
			goto exit			
		)
	)
)
:exit
if %existnet% == true (
	echo [32m运行环境检测完毕,已安装 .net framework v4.6.2运行环境[0m
) else (
	echo [31m缺少运行环境按任意键退出,安装环境后继续执行安装...[0m
	start https://download.visualstudio.microsoft.com/download/pr/8e396c75-4d0d-41d3-aea8-848babc2736a/80b431456d8866ebe053eb8b81a168b3/ndp462-kb3151800-x86-x64-allos-enu.exe
	pause>nul
exit
 )
rem 开始注册插件
echo:
echo [32m正在注册32位Office插件[OhhExcelToolBox]...[0m
echo:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe /codebase %~dp0OhhExcelToolBox.dll
echo:
echo [32m正在注册64位Office插件[OhhExcelToolBox]...[0m
echo:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /codebase %~dp0OhhExcelToolBox.dll
echo:
echo [32m正在添加Office注册表...[0m
echo:
rem 注册表操作: /v 子项名称 /t 数据类型 /d 数据 /f 不提示强行修改
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\EXCEL\Addins\OhhExcelToolBox.Connect" /f
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\EXCEL\Addins\OhhExcelToolBox.Connect" /v "FriendlyName" /t REG_SZ /d "OhhExcelToolBox" /f
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\EXCEL\Addins\OhhExcelToolBox.Connect" /v "Description" /t REG_SZ /d "OhhExcel工具箱_20230131" /f
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\EXCEL\Addins\OhhExcelToolBox.Connect" /v "LoadBehavior" /t REG_DWORD /d "3" /f
reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\EXCEL\Addins\OhhExcelToolBox.Connect" /v "CommandLineSafe" /t REG_DWORD /d "1" /f
echo:
echo [32m正在添加WPS注册表...[0m
echo:
reg add "HKEY_CURRENT_USER\Software\Kingsoft\Office\ET\AddinsWL" /f
reg add "HKEY_CURRENT_USER\Software\Kingsoft\Office\ET\AddinsWL" /v "OhhExcelToolBox.Connect" /t REG_SZ /d "" /f
echo:
echo [32m《OHH小工具集》Excel工具箱插件安装完毕!![0m
echo:
pause>nul



