功能说明 这是一款使用批处理编写的 KMS 激活脚本,支持 Office 2010/2013/2016/2019/2021 与 Windows 的激活。脚本会自动请求管理员权限,运行后输入数字并回车即可选择对应的激活项目。
使用方法
保存脚本为 .bat 文件;
在脚本中找到 set KMS_Server= 一行,填入你可用的 KMS 服务器地址 (如自建的 vlmcsd 或其他可用服务器);
双击运行,脚本会自动请求管理员权限;
根据提示输入数字(1~5)并回车,选择要激活的 Office 版本或 Windows。
注意事项
脚本默认未内置 KMS 服务器地址 ,不填写 KMS_Server 将无法激活成功;
请确保填入的 KMS 服务器可正常访问(默认端口 1688);
公开的免费 KMS 服务器随时可能失效,条件允许建议自建。
以下是完整脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 @echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" set params = %*:"="" echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin pushd "%CD%" CD /D "%~dp0" :-------------------------------------- color 2F echo. echo. echo.1.Office 2010 激活 echo. echo.2.Office 2013 激活 echo. echo.3.Office 2016 激活 echo. echo.4.Office 2019/2021 激活 echo. echo.5.Windows 激活 echo. echo. set KMS_Server= set /p c=请输入数字并回车: if %c%==1 goto 1 if %c%==2 goto 2 if %c%==3 goto 3 if %c%==4 goto 4 if %c%==5 goto 5 :office setlocal EnableDelayedExpansion reg query %strRegKey% >nul 2>nul if %errorlevel%==0 (set strCurrentKey=%strRegKey%) else (set strCurrentKey=%strRegKey6432%) for /f "delims=" %%i in ('reg query %strCurrentKey%') do ( set strInstPath=%%i set strInstPath=!strInstPath:*REG_SZ=! ) :LTrim if "%strInstPath:~0,1%"==" " set "strInstPath=%strInstPath:~1%" && goto LTrim :RTrim if "%strInstPath:~-1%"==" " set "strInstPath=%strInstPath:~0,-1%" && goto RTrim if "%strInstPath:~-1%" neq "\" set strInstPath=%strInstPath%\ echo office安装目录为%strInstPath% cd /d %strInstPath% cscript ospp.vbs /sethst:%KMS_Server% cscript ospp.vbs /setprt:1688 cscript ospp.vbs /act pause exit :office2019 cscript ospp.vbs /sethst:%KMS_Server% cscript ospp.vbs /setprt:1688 cscript ospp.vbs /act pause exit :1 set "strRegKey=HKEY_LOCAL_MACHINE\Software\Microsoft\Office\14.0\Common\InstallRoot /v Path" set "strRegKey6432=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot /v Path" goto office :2 set "strRegKey=HKEY_LOCAL_MACHINE\Software\Microsoft\Office\15.0\Common\InstallRoot /v Path" set "strRegKey6432=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot /v Path" goto office :3 set "strRegKey=HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\Common\InstallRoot /v Path" set "strRegKey6432=HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Office\16.0\Common\InstallRoot /v Path" goto office :4 (if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16")&(if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16")&(for /f %%x in ('dir /b ..\root\Licenses16\ProPlus2019VL*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&(for /f %%x in ('dir /b ..\root\Licenses16\ProPlus2019VL*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul) goto office2019 :5 cscript "%SystemRoot%\system32\slmgr.vbs" /skms %KMS_Server% cscript "%SystemRoot%\system32\slmgr.vbs" -ato pause exit