Last active
March 28, 2018 11:39
-
-
Save lxfly2000/d31a2784d36d4165238ddcbfef58f531 to your computer and use it in GitHub Desktop.
Office 2016 激活脚本(注意保存为GBK编码)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//该脚本用于激活 Office 2016. | |
//This script is written for activating Office 2016. | |
//如果有Bug或者任何疑问请邮件联系 [email protected] 或微博 lxfly2000. | |
//Any bugs or questions please contact me at [email protected] or lxfly2000 on Weibo. | |
//使用方法:在管理员模式下执行命令行“officevl <KMS服务器>” | |
//Usage: Run this command with Administrator "officevl <KMS Server>" | |
var sn="XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99";//激活序列号,可到 https://technet.microsoft.com/zh-cn/library/dn385360(v=office.16).aspx 上找。 | |
var kmsserver="";//在此处填入KMS服务器地址 | |
if(WScript.Arguments.length>0) | |
kmsserver=WScript.Arguments(0); | |
if(kmsserver==""){ | |
WScript.Echo("未指定KMS服务器地址。\n\n命令行:\nofficevl <KMS服务器>"); | |
WScript.Quit(1); | |
} | |
var wsh=new ActiveXObject("WScript.Shell"); | |
var fso=new ActiveXObject("Scripting.FileSystemObject"); | |
var officepath="%ProgramFiles(x86)%\\Microsoft Office"; | |
var temppath=""; | |
var system32path=""; | |
activate(); | |
function convertToVolumeVersion(){ | |
//打开VOL通道所需文件 | |
var lics=[ | |
"ProPlusVL_KMS_Client-ppd.xrm-ms", | |
"ProPlusVL_KMS_Client-ul.xrm-ms", | |
"ProPlusVL_KMS_Client-ul-oob.xrm-ms", | |
"ProjectProVL_KMS_Client-ppd.xrm-ms", | |
"ProjectProVL_KMS_Client-ul-oob.xrm-ms", | |
"ProjectProVL_KMS_Client-ul.xrm-ms", | |
"VisioProVL_KMS_Client-ppd.xrm-ms", | |
"VisioProVL_KMS_Client-ul-oob.xrm-ms", | |
"VisioProVL_KMS_Client-ul.xrm-ms", | |
"client-issuance-bridge-office.xrm-ms", | |
"client-issuance-root.xrm-ms", | |
"client-issuance-root-bridge-test.xrm-ms", | |
"client-issuance-stil.xrm-ms", | |
"client-issuance-ul.xrm-ms", | |
"client-issuance-ul-oob.xrm-ms", | |
"pkeyconfig-office.xrm-ms" | |
]; | |
var revver=parseInt(new Enumerator(GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_OperatingSystem")).item().Version.split(".").pop()); | |
var retCode=0; | |
for(var i=0;i<lics.length;i++){ | |
if(revver>=9200) | |
retCode=wsh.Run("cscript \""+fso.GetSpecialFolder(1)+"\\slmgr.vbs\" /ilc \""+officepath+"\\root\\Licenses16\\"+lics[i]+"\"",1,true); | |
else | |
retCode=wsh.Run("cscript \""+officepath+"\\Office16\\ospp.vbs\" /inslic:\""+officepath+"\\root\\Licenses16\\"+lics[i]+"\"",1,true); | |
if(retCode!=0){ | |
WScript.Echo("转换VOL通道时出错,可能是未以管理员方式运行或者Office安装不完整。"); | |
WScript.Quit(2); | |
} | |
} | |
} | |
function checkIfOfficeIsVolumeVersion(){ | |
var fileOutput=fso.GetSpecialFolder(2)+"\\officevl.txt"; | |
wsh.Run("cmd /c cscript \""+officepath+"\\Office16\\ospp.vbs\" /dstatus>"+fileOutput,1,true); | |
var instream=fso.OpenTextFile(fileOutput); | |
var intext=instream.ReadAll(); | |
instream.Close(); | |
fso.DeleteFile(fileOutput); | |
if(intext.indexOf("VOLUME_KMSCLIENT")!=-1)return true; | |
return false; | |
} | |
function activate(){ | |
try{ | |
officepath=wsh.RegRead("HKLM\\Software\\Microsoft\\Office\\ClickToRun\\InstallPath"); | |
}catch(e){ | |
WScript.Echo("未找到 Office 2016 安装路径。\n"+e.description); | |
return; | |
} | |
if(!checkIfOfficeIsVolumeVersion()){//如果不是VOL版 | |
if(wsh.PopUp("你安装的Office目前未使用VOL KEY,是否需要转换为VOL版激活?",0,"信息",36)!=6) | |
return; | |
convertToVolumeVersion(); | |
} | |
//激活 | |
wsh.Run("cscript \""+officepath+"\\Office16\\ospp.vbs\" /inpkey:"+sn,1,true); | |
wsh.Run("cscript \""+officepath+"\\Office16\\ospp.vbs\" /sethst:"+kmsserver,1,true); | |
wsh.Run("cscript \""+officepath+"\\Office16\\ospp.vbs\" /act",1,true); | |
WScript.Echo("操作完成。"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment