之前大佬要我做一款windows一键激活工具。基本原理是利用我们的license,从后台请求一个微软的正版license,然后调用slmgr进行windows激活。这样就可以把license的控制权留在自己这里,而不用传递给工厂,避免license流失。(所以期望从本文找破解方案的同学可以散了233)所以记录下对slmgr的研究。
slmgr是一个vba脚本,整体的结构如下图所示。可以看到整个结构基本都是面向功能的,十分容易理解。
其主要功能就是通过指定的命令进入分支语句,然后调各个功能模块方法
我们先来看看主要的入口函数ExecCommandLine。归结起来就2句话,1是执行Connect,获取WMI服务和注册表;2是根据命令参数执行不同子模块功能
Private Sub ExecCommandLine
Dim intOption, indexOption
Dim strOption, chOpt
Dim remoteInfo(3)
'省略中间的参数检测代码
'连接至本地计算机或者远端计算机,以获取WMI服务和注册表
Call Connect()
If intUnknownOption = intOption Then
LineOut GetResource("L_MsgInvalidOptions")
LineOut ""
Call DisplayUsage()
End If
'针对不同的命令参数执行子函数
intOption = ParseCommandLine(indexOption)
If intUnknownOption = intOption Then
LineOut GetResource("L_MsgUnrecognizedOption") & WScript.Arguments.Item(indexOption)
LineOut ""
Call DisplayUsage()
End If
End Sub
Connect的源码如下,其主要功能是从参数中判断是否是对本地计算机处理,针对远端计算机和本地计算机,采用不同方式获取WMI服务和注册表
Private Sub Connect
Dim objLocator, strOutput
Dim objServer, objService
Dim strErr, strVersion
On Error Resume Next
'如果是本地计算机,则直接获取WMI服务和注册表
If g_strComputer = "." Then
Set g_objWMIService = GetObject("winmgmts:\\" & g_strComputer & "\root\cimv2")
QuitIfError2("L_MsgErrorLocalWMI")
Set g_objRegistry = GetObject("winmgmts:\\" & g_strComputer & "\root\default:StdRegProv")