Vbs脚本执行不同版本的Windows OS激活任务(MAK&KMS激活)
我们前面几面都介绍了关于vbs脚本程序来完成一些半自动化的任务,今天我们介绍一下,Vbs脚本执行不同版本的Windows OS激活任务(MAK&KMS激活)的功能介绍,其实不管通过vbs实现什么样的功能,我们还是需要屡清思路来完成相关逻辑程序的编写及运行。我们今天既然要使用vbs脚本来完成不同版本的激活任务,而且不同版本的OS也有不同的MAK Key,所以我们需要通过获取系统的版本来完成对应的OS激活任务。同样,我们需要为用户定义激活程序,只有指定的MAC地址才能完成激活任务,所以我们逻辑思路有两个,1.获取用户MAC地址.2获取用户的系统版本(windows7、windows8、windows10、windows2008R2、windows2012R2……..)。3通过用户不同版本的OS来完成对应的OS key的导入及激活。具体见下:
首先是获取用户的MAC地址
Set mc = GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration") For Each mo In mc If mo.IPEnabled = True Then 'TracePrint "本机网卡MAC地址是: " & mo.MacAddress GetMAC = mo.MacAddress Exit For End If Next msgbox getmac
然后我们需要获取系统的OS版本;
因为当前系统的版本很多(windows7、windows8、windows10、windows2008R2、windows2012R2……..),所以我们需要获取系统版本;
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objItem in colItems strOSVersion = objItem.Version OSVersion = objItem.Caption Next GetOSVersion=OSVersion msgbox getosversion
满足以上条件后,我们就可以嵌套代码了,我们需要定义两个函数,一个为:获取用户系统版本,另外一个为获取用户的MAC地址。然后通过条件进行判断执行
我们定义当获取用户版本为windows7 企业版本或者专业版本的导入指定的key,然后完成激活。然后获取为windows10企业版或者专业版导入指定的key,然后完成激活。
if GetMAC() <> "44:37-e6:20-f8:03" Then SET Wshell=CreateObject("Wscript.Shell") CreateObject("Wscript.Shell").Popup "Please Wait for Activing ...", 3, "MsgBox", 64 msgbox "mac address:" & GetMAC() & Chr(13) & "OSVersion:" & GetOSVersion() & Chr(13) if GetOSVersion() = "Microsoft Winodws 7 企业版" Or GetOSVersion() = "Microsoft Winodws 7 专业版" then Wshell.Run "slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx",0,True Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows 10 企业版" Or GetOSVersion() = "Microsoft Windows 10 专业版" Then Wshell.Run "slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx",0,True Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows Server 2012 R2 Datacenter" Or GetOSVersion() = "Microsoft Windows Server 2012 R2 Standard" then Wshell.Run "slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx",0,True Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows 10 企业版" Then Wshell.Run "slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx",0,True Wshell.Run "slmgr.vbs /ato",0,True End If msgbox "Active Success" Else msgbox "Active Failed" End If Function GetMAC() GetMAC = "" Dim mc,mo Set mc = GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration") For Each mo In mc If mo.IPEnabled = True Then 'TracePrint "本机网卡MAC地址是: " & mo.MacAddress GetMAC = mo.MacAddress Exit For End If Next Set mc = nothing End Function Function GetOSVersion() strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objItem in colItems strOSVersion = objItem.Version OSVersion = objItem.Caption Next GetOSVersion=OSVersion End Function
我们完成了MAK激活后,我们如果定义使用KMS激活呢,其实使用KMS激活就简单了,我们只需要将原来的代码从导入ipk修改为skms激活。因为我们都知道使用kms激活的命令为:
'KMS激活命令如下: 'Slmgr.vbs /skms kmshosts.abc.com:1688 'Slmgr.vbs /ato 所以修改后的代码为:见下: if GetMAC() <> "44:37-e6:20-f8:03" Then SET Wshell=CreateObject("Wscript.Shell") CreateObject("Wscript.Shell").Popup "Please Wait for Activing ...", 3, "MsgBox", 64 'msgbox "mac address:" & GetMAC() & Chr(13) & "OSVersion:" & GetOSVersion() & Chr(13) if GetOSVersion() = "Microsoft Winodws 7 企业版" Or GetOSVersion() = "Microsoft Winodws 7 专业版" then Wshell.Run "slmgr.vbs /skms bj-actsrv02.beyondsoft.com",0,True Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows 10 企业版" Or GetOSVersion() = "Microsoft Windows 10 专业版" Then Wshell.Run "slmgr.vbs /skms bj-actsrv02.beyondsoft.com",0,True msgbox "slmgr.vbs /ato" Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows 8.1 专业版" then Wshell.Run "slmgr.vbs /skms bj-actsrv02.beyondsoft.com:1688",0,True Wshell.Run "slmgr.vbs /ato",0,True Elseif GetOSVersion() = "Microsoft Windows Server 2012 R2 Datacenter" Or GetOSVersion() = "Microsoft Windows Server 2012 R2 Standard" then Wshell.Run "slmgr.vbs /skms bj-actsrv02.beyondsoft.com",0,True Wshell.Run "slmgr.vbs /ato",0,True End If msgbox "Active Success" Else msgbox "Active Failed" End If Function GetMAC() GetMAC = "" Dim mc,mo Set mc = GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration") For Each mo In mc If mo.IPEnabled = True Then 'TracePrint "本机网卡MAC地址是: " & mo.MacAddress GetMAC = mo.MacAddress Exit For End If Next Set mc = nothing End Function Function GetOSVersion() strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For Each objItem in colItems strOSVersion = objItem.Version OSVersion = objItem.Caption Next GetOSVersion=OSVersion End Function
定义好后,我们也同样可以使用之前文章中介绍的访问,然后将vbs脚本使用工具封装成exe,这样就提高了安全性
本文出自 “高文龙” 博客,谢绝转载!