ThunderEX/py-kms

可用的KMS服务器

然后找到个似乎不错的:https://kms.nases.win/

提供Windows批处理脚本,直接下载【KMS.cmd】(备份:KMS.cmd)用管理员身份运行应该就可以了。

备份的格式转为了GB2312,中文Windows系统CMD命令提示符的默认编码似乎是936(ANSI/OEM - 简体中文 GBK),我在虚拟机中运行直接下载的批处理脚本(UTF-8),运行的时候乱码了。

KMS批处理脚本

我觉得有必要贴一下完整的批处理脚本,毕竟文件不大,要是那个网站因为各种原因关闭了呢!还可以去别处找KMS服务器,然后简单修改就可以使用。

只要修改下面代码中KMSHostKMSPort的参数,保存为cmd格式,再运行。

@echo off

title KMS通用激活工具

:: 获取脚本路完全路径
set _FilePath=%~f0

:: 获取脚本当前路径
set _FileDir=%~dp0

setlocal EnableExtensions EnableDelayedExpansion

set "KMSHost=kms.nases.win"

set "KMSPort=1688"

color 3e & cd /d "%_FileDir%"

%1 %2

:: uac
fltmc >nul 2>&1 || (
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\GetAdmin.vbs"
    echo UAC.ShellExecute "!_FilePath!", "", "", "runas", 1 >> "%temp%\GetAdmin.vbs"
    cmd /u /c type "%temp%\GetAdmin.vbs">"%temp%\GetAdminUnicode.vbs"
    cscript //nologo "%temp%\GetAdminUnicode.vbs"
    del /f /q "%temp%\GetAdmin.vbs" >nul 2>&1
    del /f /q "%temp%\GetAdminUnicode.vbs" >nul 2>&1
    exit
)

::mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :start","","runas",1)(window.close)&goto :eof

goto CheckKMSServer

::============================================
:: 检查KMS服务器
:CheckKMSServer
echo 正在检查与激活服务器的连接情况 ... 
echo.
ping %KMSHost% | find "TTL"  > NUL && (
    echo 成功连接上服务器
    echo.
    goto SLSActivation
)
cls
echo 无法连接到服务器
call :Close

::============================================
:SLSActivation
ver | find "6.0." > NUL &&  goto Select6
ver | find "6.1." > NUL &&  goto Select7
ver | find "6.2." > NUL &&  goto Select8
ver | find "6.3." > NUL &&  goto Select8.1
ver | find "10.0." > NUL &&  goto Select10
echo 当前系统不支持
goto OSPSActivation

::============================================
::office
:OSPSActivation
echo ============================================
echo 检查安装的 office
call :CheckOffice14
call :CheckOffice15
call :CheckOffice16
call :Close

::============================================
:Select6
echo 当前为Windows Vista/2008
set Business=YFKBB-PQJJV-G996G-VWGXY-2V3X8
set BusinessN=HMBQG-8H2RH-C77VX-27R82-VMQBT
set Enterprise=VKK3X-68KWM-X2YGT-QR4M6-4BWMV
set EnterpriseN=VTC42-BM838-43QHV-84HX6-XJXKV
set ServerWeb=WYR28-R7TFJ-3X2YQ-YCY4H-M249D
set ServerStandard=TM24T-X9RMF-VWXK6-X8JC9-BFGM2
set ServerStandardV=W7VD6-7JFBR-RX26B-YKQ3Y-6FFFJ
set ServerEnterprise=YQGMW-MPWTJ-34KDK-48M3W-X4Q6V
set ServerEnterpriseV=39BXF-X8Q23-P2WWT-38T2F-G3FPG
set ServerWeb=RCTX3-KWVHP-BR6TB-RB6DM-6X7HP
set ServerDatacenter=7M67G-PC374-GR742-YH8V4-TCBY3
set ServerDatacenterV=22XQ2-VRXRG-P8D42-K34TD-G3QQC
set ServerEnterpriseIA64=4DWFP-JF3DJ-B7DTH-78FJB-PDRHK
goto ActiveOS

::============================================
:Select7
echo 当前为Windows 7/Windows Server 2008 R2
set Professional=FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4
set ProfessionalN=MRPKT-YTG23-K7D7T-X2JMM-QY7MG
set ProfessionalE=W82YF-2Q76Y-63HXB-FGJG9-GF7QX
set Enterprise=33PXH-7Y6KF-2VJC9-XBBR8-HVTHH
set EnterpriseN=YDRBP-3D83W-TY26F-D46B2-XCKRJ
set EnterpriseE=C29WB-22CC8-VJ326-GHFJW-H9DH4
set ServerWeb=6TPJF-RBVHG-WBW2R-86QPH-6RTM4
set ServerHPC=TT8MH-CG224-D3D7Q-498W2-9QCTX
set ServerStandard=YC6KT-GKW9T-YTKYR-T4X34-R7VHC
set ServerEnterprise=489J6-VHDMP-X63PK-3K798-CPX3Y
set ServerDatacenter=74YFP-3QFB3-KQT8W-PMXWJ-7M648
set ServerEnterpriseIA64=GT63C-RJFQ3-4GMB6-BRFB9-CB83V
goto ActiveOS

::============================================
:Select8
echo 当前为 Windows 8 / Windows Server 2012
set Professional=NG4HW-VH26C-733KW-K6F98-J8CK4
set ProfessionalN=XCVCF-2NXM9-723PB-MHCB7-2RYQQ
set Core=BN3D2-R7TKB-3YPBD-8DRP2-27GG4
set Enterprise=32JNW-9KQ84-P47T8-D8GGY-CWCK7
set EnterpriseN=JMNMF-RHW7P-DMY6X-RF3DR-X2BQT
set CoreN=8N2M2-HWPGY-7PGT9-HGDD8-GVGGY
set CoreSingleLanguage=2WN2H-YGCQR-KFX6K-CD6TF-84YXQ
set CoreCountrySpecific=4K36P-JN4VD-GDC6V-KDT89-DYFKP
set ServerMultiPointPremium=XNH6W-2V9GX-RGJ4K-Y8X6F-QGJ2G
set ServerMultiPointStandard=HM7DN-YVMH3-46JC3-XYTG7-CYQJJ
set ServerStandard=XC9B7-NBPP2-83J2H-RHMBY-92BT4
set ServerDatacenter=48HP8-DN98B-MYWDG-T2DCC-8W83P
goto ActiveOS

::============================================
:Select8.1
echo 当前为 Windows 8.1 / Windows Server 2012 R2
set Professional=GCRJD-8NW9H-F2CDX-CCM8D-9D6T9
set ProfessionalN=HMCNV-VVBFX-7HMBH-CTY9B-B4FXY
set Enterprise=MHF9N-XY6XB-WVXMC-BTDCT-MKKG7
set EnterpriseN=TT4HM-HN7YT-62K67-RGRQJ-JFFXW
set ServerSolution=KNC87-3J2TX-XB4WP-VCPJV-M4FWM
set ServerStandard=D2N9P-3P6X9-2R39C-7RTCD-MDVJX
set ServerDatacenter=W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9
set Essentials=KNC87-3J2TX-XB4WP-VCPJV-M4FWM
goto ActiveOS

::============================================
:Select10
echo 当前为 Windows 10 / Windows Server 2016
set Core=TX9XD-98N7V-6WMQ6-BX7FG-H8Q99
set CoreCountrySpecific=PVMJN-6DFY6-9CCP6-7BKTT-D3WVR
set CoreN=3KHY7-WNT83-DGQKR-F7HPR-844BM
set CoreSingleLanguage=7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH
set Professional=W269N-WFGWX-YVC9B-4J6C9-T83GX
set ProfessionalN=MH37W-N47XK-V7XM9-C7227-GCQG9
set Enterprise=NPPR9-FWDCX-D2C8J-H872K-2YT43
set EnterpriseN=DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4
set Education=NW6C2-QMPVW-D7KKK-3GKT6-VCFB2
set EducationN=2WH4N-8QGBV-H22JP-CT43Q-MDWWJ
set EnterpriseS=WNMTR-4C88C-JK8YV-HQ7T2-76DF9
set EnterpriseSN=2F77B-TNFGY-69QQF-B8YKP-D69TJ
:: Server 2016
set ServerDatacenter=CB7KF-BWN84-R7R2Y-793K2-8XDDG
set ServerStandard=WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY
set ServerEssentials=JCKRF-N37P4-C2D82-9YXRT-4M63B

goto ActiveOS

::============================================
::系统激活
:ActiveOS
for /f "tokens=3 delims= " %%i in ('reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "EditionID"') do set EditionID=%%i
if defined %EditionID% (
        cscript //Nologo %windir%\system32\slmgr.vbs /ipk !%EditionID%!
        cscript //Nologo %windir%\system32\slmgr.vbs /skms %KMSHost%:%KMSPort%
        cscript //Nologo %windir%\system32\slmgr.vbs /ato
) else (
        echo 无法识别系统版本
)
goto OSPSActivation


::============================================
:: office 激活
:ActiveOffice
if DEFINED _Office%1Path (
    cd /d "!_Office%1Path!"
    if %1 EQU 16 call :installKeyOffice16
    echo.&echo 尝试激活 %2 ...&echo.
    cscript //nologo ospp.vbs /sethst:%KMSHost%:%KMSPort% >nul
    cscript //nologo ospp.vbs /act | find /i "successful" && (
        echo.&echo ***** %2 激活成功 ***** & echo.) || (echo.&echo ***** %2 激活失败 ***** & echo.)
)    
cd /d "%_FileDir%"
goto :EOF

::============================================
:: office16 激活
:installKeyOffice16
for /f %%x in ('dir /b ..\root\Licenses16\projectprovl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul
for /f %%x in ('dir /b ..\root\Licenses16\proplusvl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul
for /f %%x in ('dir /b ..\root\Licenses16\standardvl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul
for /f %%x in ('dir /b ..\root\Licenses16\visioprovl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul
cscript ospp.vbs /inpkey:NYH39-6GMXT-T39D4-WVXY2-D69YY >nul
cscript ospp.vbs /inpkey:7WHWN-4T7MP-G96JF-G33KR-W8GF4 >nul
cscript ospp.vbs /inpkey:RBWW7-NTJD4-FFK2C-TDJ7V-4C2QP >nul
cscript ospp.vbs /inpkey:XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99 >nul
cscript ospp.vbs /inpkey:YG9NW-3K39V-2T3HJ-93F3Q-G83KT >nul
cscript ospp.vbs /inpkey:PD3PC-RHNGV-FXJ29-8JK7D-RJRJK >nul
goto :EOF

::============================================
:CheckOffice14
call :CheckOfficePath 14 Office2010
goto :EOF

::============================================
:CheckOffice15
call :CheckOfficePath 15 Office2013
goto :EOF

::============================================
:CheckOffice16
echo.&echo 正在检测 Office2016 系列产品 ...
if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" set _Office16Path=%ProgramFiles%\Microsoft Office\Office16
if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" set _Office16Path=%ProgramFiles(x86)%\Microsoft Office\Office16
if DEFINED _Office16Path (
    echo.
    echo 已发现 Office2016
    call :ActiveOffice 16 Office2016
  ) else (echo.&echo 未发现 Office2016)
goto :EOF

::============================================
:CheckOfficePath
echo.&echo 正在检测 %2 系列产品 ...
set _Office%1Path=
set _Reg32=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\%1.0\Common\InstallRoot
set _Reg64=HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\%1.0\Common\InstallRoot
reg query "%_Reg32%" /v "Path" > nul 2>&1 && FOR /F "tokens=2*" %%a IN ('reg query "%_Reg32%" /v "Path"') do SET "_OfficePath1=%%b"
reg query "%_Reg64%" /v "Path" > nul 2>&1 && FOR /F "tokens=2*" %%a IN ('reg query "%_Reg64%" /v "Path"') do SET "_OfficePath2=%%b"
if DEFINED _OfficePath1 (if exist "%_OfficePath1%ospp.vbs" set _Office%1Path=!_OfficePath1!)
if DEFINED _OfficePath2 (if exist "%_OfficePath2%ospp.vbs" set _Office%1Path=!_OfficePath2!)
set _OfficePath1=
set _OfficePath2=
if DEFINED _Office%1Path (echo.&echo 已发现 %2) else (echo.&echo 未发现 %2)
call :ActiveOffice %1 %2
goto :EOF


::============================================
:Close
echo.
echo 5 秒后自动关闭
ping 127.0.0.1 -n 6 >nul 2>&1
exit

KMS激活用到的序列号

上面脚本里已经有了;其他的话,另外搜索找吧,然后用本文下面的手动激活方法激活。

如何搭建KMS服务器

环境寻求

似乎只要求Python

Python 2.7.x or Python 2.6.x with the "argparse" module installed.

示例环境

Debian 8 (Jessie) :

apt-get update && apt-get install -y aptitude && aptitude -y dist-upgrade
aptitude install -y python git

获取代码

cd /opt
git clone https://github.com/myanaloglife/py-kms.git

设置开机自启

echo 'kms:x:501:65534::/nonexistent:/bin/false' >> /etc/passwd
echo 'kms:*:16342:0:99999:7:::' >> /etc/shadow

echo '[Unit]' > /etc/systemd/system/py-kms.service
echo 'Description=Python KMS Server' >> /etc/systemd/system/py-kms.service
echo >> /etc/systemd/system/py-kms.service
echo '[Service]' >> /etc/systemd/system/py-kms.service
echo 'ExecStart=/usr/bin/python /opt/py-kms/server.py' >> /etc/systemd/system/py-kms.service
echo 'User=kms' >> /etc/systemd/system/py-kms.service
echo 'Restart=always' >> /etc/systemd/system/py-kms.service
echo 'RestartSec=1' >> /etc/systemd/system/py-kms.service
echo >> /etc/systemd/system/py-kms.service
echo '[Install]' >> /etc/systemd/system/py-kms.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/py-kms.service
systemctl enable py-kms.service
systemctl start py-kms.service

测试是否搭建成功

## 默认端口是1688
python /opt/py-kms/client.py server_address [port]

2017-08-25_162340.png

注意事项

有效期

  • KMS方式激活的有效期为180天;
  • 每隔一段时间系统会自动连接KMS服务器请求续期;
  • KMS服务器一直稳定在线的话,续期是自动完成的。

激活失败或输入过其他密钥

如果激活失败或输入过其他密钥,请先替换为微软官方密钥(传送门)。

手动激活方法

Windows VOL:

用管理员身份打开命令提示符,分别执行以下:

::cd /d "%SystemRoot%\system32"
slmgr /skms kms.nases.win
slmgr /ato
slmgr /xpr

Windows:

VOL版的Windows,用KMS激活需要用到序列号,同样是管理员身份打开命令提示符,然后示例:

slmgr.vbs -upk
slmgr.vbs -ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
slmgr.vbs -skms kms.nases.win
slmgr.vbs -ato
slmgr.vbs -dlv

Office VOL:

用管理员身份打开命令提示符,进入软件安装目录,示例(Office 2016):

cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16"
cd /d "%ProgramFiles%\Microsoft Office\Office16"

然后再执行:

cscript ospp.vbs /sethst:kms.nases.win
cscript ospp.vbs /act
cscript ospp.vbs /dstatus

END

到处看资料看的有点乱了,手动激活方法似乎有些乱,或是不准确,一一测试的话太费时间;额,不折腾了,先这样。