Vbs腳本執行不一樣版本的Windows OS激活任務(MAK&KMS激活)shell
咱們前面幾面都介紹了關於vbs腳本程序來完成一些半自動化的任務,今天咱們介紹一下,Vbs腳本執行不一樣版本的Windows OS激活任務(MAK&KMS激活)的功能介紹,其實無論經過vbs實現什麼樣的功能,咱們仍是須要屢清思路來完成相關邏輯程序的編寫及運行。咱們今天既然要使用vbs腳原本完成不一樣版本的激活任務,並且不一樣版本的OS也有不一樣的MAK Key,因此咱們須要經過獲取系統的版原本完成對應的OS激活任務。一樣,咱們須要爲用戶定義激活程序,只有指定的MAC地址才能完成激活任務,因此咱們邏輯思路有兩個,1.獲取用戶MAC地址.2獲取用戶的系統版本(windows七、windows八、windows十、windows2008R二、windows2012R2……..)。3經過用戶不一樣版本的OS來完成對應的OS key的導入及激活。具體見下:windows
首先是獲取用戶的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版本;bash
由於當前系統的版本不少(windows七、windows八、windows十、windows2008R二、windows2012R2……..),因此咱們須要獲取系統版本;ide
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激活的命令爲:3d
'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,這樣就提升了安全性blog