|
@echo off
::CMD窗口字体绿色
title %~n0
color 0a
setlocal EnableDelayedExpansion
set "m_Office版本号="
set "m_Office系统位数="
set "m_Office安装目录="
set "m_Office系统位数=64"
call :扫描注册表一级子目录并回调 "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office" ":检查激活Office"
set "m_Office系统位数=32"
call :扫描注册表一级子目录并回调 "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office" ":检查激活Office"
echo.
pause
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:检查激活Office
set "m_Office版本号="
set "m_Office安装目录="
set "m_ospp文件目录="
call :查询注册表一个数值 "m_Office安装目录" "%~1\Common\InstallRoot" "Path"
if "" EQU "!m_Office安装目录!" call :查询注册表一个数值 "m_Office安装目录" "%~1\Excel\InstallRoot" "Path"
if "" EQU "!m_Office安装目录!" call :查询注册表一个数值 "m_Office安装目录" "%~1\Word\InstallRoot" "Path"
if "" NEQ "!m_Office安装目录!" if exist "!m_Office安装目录!" (
for %%a in ( "%~1" ) do set "m_Office版本号=%%~na"
if "\" EQU "!m_Office安装目录:~-1!" set "m_Office安装目录=!m_Office安装目录:~0,-1!"
set "m_ospp文件目录=!m_Office安装目录!"
cd /d "!m_Office安装目录!"
if not exist "!m_Office安装目录!\ospp.vbs" (
set "m_ospp文件目录="
cd /d "..\..\Office!m_Office版本号!"
if exist "ospp.vbs" for /f "delims=*" %%a in ( 'cd' ) do set "m_ospp文件目录=%%a"
)
echo.
echo --------------------------------------------------------
echo 准备激活:!m_Office系统位数!位 Office 20!m_Office版本号!
echo 系统位数:!m_Office系统位数!
echo 安装版本:!m_Office版本号!
echo 安装路径:!m_Office安装目录!
echo ospp文件目录:!m_ospp文件目录!
if not exist "!m_ospp文件目录!\ospp.vbs" (
echo 无法找到激活文件:ospp.vbs 在目录:!m_ospp文件目录!
echo 激活失败!
goto :eof
)
if "16" EQU "!m_Office版本号!" (
call :安装2016证书
call :安装2019证书
call :安装2021证书
)>nul 2>nul
if "19" EQU "!m_Office版本号!" ( call :安装2019证书 )>nul 2>nul
if "21" EQU "!m_Office版本号!" ( call :安装2021证书 )>nul 2>nul
call :设置KMS服务器并激活
)
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:扫描注册表一级子目录并回调
rem :扫描注册表一级子目录并回调 "in" "in"
rem :参数列表 注册表路径 回调标签
( Reg Query "%~1" )>nul 2>nul || (
goto :eof
)
rem if 0 NEQ %errorlevel% (
rem goto :eof
rem )
if "" EQU "%~2" for /f "delims=*" %%a in ( 'Reg Query "%~1" ' ) do if "" NEQ "%%a" call :扫描注册表一级子目录并回调_001 "%%a" "%~1"
if "" NEQ "%~2" for /f "delims=*" %%a in ( 'Reg Query "%~1" ' ) do if "" NEQ "%%a" call :扫描注册表一级子目录并回调_002 "%%a" "%~1" "%~2"
goto :eof
:扫描注册表一级子目录并回调_001
echo x%~1 | findstr /i "%~2" >nul 2>nul && echo %~1
goto :eof
:扫描注册表一级子目录并回调_002
echo x%~1 | findstr /i "%~2" >nul 2>nul && call %~3 "%~1"
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:查询注册表一个数值
rem :查询注册表一个数值 "inout_ptr" "in" "in"
rem :参数列表 输出的数值变量名 注册表路径 [注册表数值名,如果空则查询默认值]
( Reg Query "%~2" )>nul 2>nul || (
goto :eof
)
if "" NEQ "%~1" set "%~1="
if "" NEQ "%~3" (
for /f "delims=*" %%a in ( 'Reg Query "%~2" /v "%~3" ' ) do if "" NEQ "%%a" if "" NEQ "%~1" (
set "查询注册表一个数值_临时变量=%%a"
set "查询注册表一个数值_临时变量=!查询注册表一个数值_临时变量: %~3 =!"
for /f "tokens=1,* delims= " %%b in ( "!查询注册表一个数值_临时变量!" ) do set "查询注册表一个数值_输出数值=%%c"
set "%~1=!查询注册表一个数值_输出数值!"
)
goto :eof
)>nul 2>nul
for /f "delims=*" %%a in ( 'Reg Query "%~2" /ve ' ) do if "" NEQ "%%a" if "" NEQ "%~1" (
set "查询注册表一个数值_临时变量=%%a"
set "查询注册表一个数值_临时变量=!查询注册表一个数值_临时变量: %~3 =!"
for /f "tokens=1,* delims= " %%b in ( "!查询注册表一个数值_临时变量!" ) do set "查询注册表一个数值_输出数值=%%c"
set "%~1=!查询注册表一个数值_输出数值!"
)>nul 2>nul
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|