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地址

clip_image002

1
2
3
4
5
6
7
8
9
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

clip_image004

然后我们需要获取系统的OS版本;

因为当前系统的版本很多(windows7、windows8、windows10、windows2008R2、windows2012R2……..),所以我们需要获取系统版本;

clip_image006

1
2
3
4
5
6
7
8
9
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

clip_image007

满足以上条件后,我们就可以嵌套代码了,我们需要定义两个函数,一个为:获取用户系统版本,另外一个为获取用户的MAC地址。然后通过条件进行判断执行

我们定义当获取用户版本为windows7 企业版本或者专业版本的导入指定的key,然后完成激活。然后获取为windows10企业版或者专业版导入指定的key,然后完成激活。

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
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

wKiom1XtgrngRwRZAAHBzhPdsqA571.jpg

wKioL1XthOOQKYqTAAGkc90CbUU557.jpg

wKiom1Xtgrmx5_GTAAHKPIT-yj8009.jpg

wKioL1XthOORt4UkAAGx4VYkvck280.jpg

wKiom1XtgrqD7dJnAAJmKZbFO9c128.jpg

我们完成了MAK激活后,我们如果定义使用KMS激活呢,其实使用KMS激活就简单了,我们只需要将原来的代码从导入ipk修改为skms激活。因为我们都知道使用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
'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,这样就提高了安全性




本文转自 高文龙 51CTO博客,原文链接:http://blog.51cto.com/gaowenlong/1692492,如需转载请自行联系原作者

相关文章
|
1月前
|
网络协议 数据安全/隐私保护 Windows
Windows Server 各版本搭建域控制器实现通过域管理用户(03~19)
Windows Server 各版本搭建域控制器实现通过域管理用户(03~19)
46 1
|
1月前
|
存储 数据安全/隐私保护 索引
Windows Server 各版本搭建文件服务器实现共享文件(03~19)
Windows Server 各版本搭建文件服务器实现共享文件(03~19)
166 1
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows Server 2012 操作系统保姆级教程(附链接)
79 0
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
92 0
如何在 VM 虚拟机中安装 Windows 7 操作系统保姆级教程(附链接)
|
1月前
|
数据安全/隐私保护 虚拟化 Windows
如何在 VM 虚拟机中安装 Windows XP 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Windows XP 操作系统保姆级教程(附链接)
125 0
|
2月前
|
数据安全/隐私保护 网络虚拟化 开发者
appuploder 全过程使用教程(Windows 版本)
appuploder 全过程使用教程(Windows 版本)
|
2月前
|
弹性计算 运维 安全
阿里云服务器Windows和Linux操作系统区别对比
阿里云服务器Windows和Linux操作系统区别对比,性能有差异吗?有,同配置下Linux性能要优于Windows,但这与阿里云无关,仅仅是linux和windows之间的区别。另外,阿里云提供的windows和linux操作系统均为正版授权,用户不需要额外支付许可费用,如何选择?看用户自己的应用程序情况。
|
14天前
|
Windows
【Windows】 手写脚本更快编辑hosts文件
【Windows】 手写脚本更快编辑hosts文件
15 0
|
23天前
|
Python Windows
【Python】Windows如何在cmd中切换python版本
【Python】Windows如何在cmd中切换python版本
|
1月前
|
监控 API 数据库
Python语言Windows操作系统
Python语言Windows操作系统

热门文章

最新文章