Showing posts with label MAK. Show all posts
Showing posts with label MAK. Show all posts

Friday, October 2, 2015

Capturing Windows Activation Key by SCCM

Most of the enterprise that are using Windows as the Operating System would most likely be using Microsoft Multiple Activation Keys or MAk for short for licensing.
There maybe a day which come when you may need to figure out how to get the number of clients in your environment that are activated using a particular product key. (This will NOT work for MAK but if needed, you can still use the generated product ID to tied to a valid ID)
This information unfortunately is not readily available in SCCM and would require some work to have it available.

The VBS that has been written below enables you to be able to retrieve the MAK and store it in a registry key (in the script, I have stored it on HKLM\Software\SCCM\ActivationKey).
Once you have this value available, you will be able to by means of SCCM to do a hardware inventory to retrieve the information and format it accordingly for use.
Hopefully this helps anyone who requires this.

Option Explicit 

Const HKEY_LOCAL_MACHINE = &H80000002
Dim objshell,path,DigitalID, Result ,Strcomputer,objregistry,strkeypath,strvaluename,strvalue,strvaluename1
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId4")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
ProductKey = ConvertToKey(DigitalID) 
ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey
'wscript.echo ProductData

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")

'Check for the existance of the key and create if it's not found.
strKeyPath = "SOFTWARE\SCCM\"
strValueName = "ActivationKey"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

If IsNull(strValue) Then

objregistry.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
StrValueName1 = "ActivationKey"

objRegistry.SetStringValue HKEY_Local_Machine, strKeyPath, strValueName1,ProductKey

End If

'Convert binary to chars
Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    'Check if OS is Windows 8
    isWin8 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
    i = 24
    Maps = "BCDFGHJKMPQRTVWXY2346789"
    Do
        Current= 0
        j = 14
        Do
           Current = Current* 256
           Current = Key(j + KeyOffset) + Current
           Key(j + KeyOffset) = (Current \ 24)
           Current=Current Mod 24
            j = j -1
        Loop While j >= 0
        i = i -1
        KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
        Last = Current
    Loop While i >= 0 
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = "N"
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
   
    
End Function