File: C:/Windows/OEM/Licensing.wsf
<package>
<?component error="true" debug="true" ?>
<comment>
Configures the SPP subsystem to use Volume Licensing.
Note: this component does not work during the specialize pass.
Note: EVAL OS is left untouched.
</comment>
<component id="SoftwareLicensing">
<registration
progid="WaGuest.SoftwareLicensing"
description=""
version="1.0.0.0"
clsid="{536B8407-6D25-42B5-9A86-7FCE0DCE9C46}"/>
<public>
<property name="WScript" />
<method name="Initialize" />
<method name="ConfigureLicensing" />
</public>
<object id="WshShell" progid="WScript.Shell" />
<script language="VBScript" src="Utility.vbs" />
<script language="VBScript">
Class License
Public ProductId
Public PartialKey
Public Family
Public Description
Public HasEvaluationEndDate
Public Name
End Class
private const KeyManagementServicePort = 1688
private const WindowsAppId = "55c92734-d682-4d71-983e-d6ec3f16059f"
Dim g_Trace
Dim g_OSBuildNumber
Dim g_objKeyDictionaryWin7
Dim g_objKeyDictionaryWin8
Dim g_objKeyDictionaryWin8R2
Dim g_objKeyDictionaryServer2012R2AVMA
Dim g_objKeyDictionaryWin10
Dim g_objKeyDictionaryServer2016AVMA
Dim g_objKeyDictionary2019
Dim g_objKeyDictionaryServer2019AVMA
Dim g_objKeyDictionaryServer2022AVMA
Dim g_objLicense : Set g_objLicense = Nothing
Dim oTraceEvent
Set g_objKeyDictionaryWin7 = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryWin8 = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryWin8R2 = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryServer2012R2AVMA = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryWin10 = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryServer2016AVMA = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionary2019 = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryServer2019AVMA = CreateObject("Scripting.Dictionary")
Set g_objKeyDictionaryServer2022AVMA = CreateObject("Scripting.Dictionary")
' Keys picked from: https://technet.microsoft.com/en-US/jj612867.aspx
' Windows 7 & Windows server 2008 or 2008 R2
g_objKeyDictionaryWin7.Add "Business", "FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4" ' Windows 7 Business
g_objKeyDictionaryWin7.Add "BusinessN", "MRPKT-YTG23-K7D7T-X2JMM-QY7MG" ' Windows 7 BusinessN
g_objKeyDictionaryWin7.Add "BusinessE", "W82YF-2Q76Y-63HXB-FGJG9-GF7QX" ' Windows 7 BusinessE
g_objKeyDictionaryWin7.Add "Enterprise", "33PXH-7Y6KF-2VJC9-XBBR8-HVTHH" ' Windows 7 Enterprise
g_objKeyDictionaryWin7.Add "EnterpriseN", "YDRBP-3D83W-TY26F-D46B2-XCKRJ" ' Windows 7 EnterpriseN
g_objKeyDictionaryWin7.Add "EnterpriseE", "C29WB-22CC8-VJ326-GHFJW-H9DH4" ' Windows 7 EnterpriseE
g_objKeyDictionaryWin7.Add "ServerComputeCluster", "FKJQ8-TMCVP-FRMR7-4WR42-3JCD7" ' Windows 7 Server Compute Cluster
g_objKeyDictionaryWin7.Add "ServerDatacenter", "74YFP-3QFB3-KQT8W-PMXWJ-7M648" ' Windows 7 Server Data Center & Core
g_objKeyDictionaryWin7.Add "ServerEnterprise", "489J6-VHDMP-X63PK-3K798-CPX3Y" ' Windows 7 Server Enterprise
g_objKeyDictionaryWin7.Add "ServerEnterpriseIA64", "GT63C-RJFQ3-4GMB6-BRFB9-CB83V" ' Windows 7 Server Enterprise Itanium Edition
g_objKeyDictionaryWin7.Add "ServerStandard", "YC6KT-GKW9T-YTKYR-T4X34-R7VHC" ' Windows 7 Server Standard
g_objKeyDictionaryWin7.Add "ServerWeb", "6TPJF-RBVHG-WBW2R-86QPH-6RTM4" ' Windows 7 Server Web
' Windows 8 & Windows server 2012
g_objKeyDictionaryWin8.Add "Core", "BN3D2-R7TKB-3YPBD-8DRP2-27GG4" '
g_objKeyDictionaryWin8.Add "CoreARM", "DXHJF-N9KQX-MFPVR-GHGQK-Y7RKV" '
g_objKeyDictionaryWin8.Add "CoreCountrySpecific", "4K36P-JN4VD-GDC6V-KDT89-DYFKP" '
g_objKeyDictionaryWin8.Add "CoreN", "8N2M2-HWPGY-7PGT9-HGDD8-GVGGY" '
g_objKeyDictionaryWin8.Add "CoreSingleLanguage", "2WN2H-YGCQR-KFX6K-CD6TF-84YXQ" '
g_objKeyDictionaryWin8.Add "Enterprise", "32JNW-9KQ84-P47T8-D8GGY-CWCK7" '
g_objKeyDictionaryWin8.Add "EnterpriseN", "JMNMF-RHW7P-DMY6X-RF3DR-X2BQT" '
g_objKeyDictionaryWin8.Add "Professional", "NG4HW-VH26C-733KW-K6F98-J8CK4" '
g_objKeyDictionaryWin8.Add "ProfessionalN", "XCVCF-2NXM9-723PB-MHCB7-2RYQQ" '
g_objKeyDictionaryWin8.Add "ProfessionalWMC", "GNBB8-YVD74-QJHX6-27H4K-8QHDG" '
g_objKeyDictionaryWin8.Add "ServerDatacenter", "48HP8-DN98B-MYWDG-T2DCC-8W83P" '
g_objKeyDictionaryWin8.Add "ServerDatacenterCore", "48HP8-DN98B-MYWDG-T2DCC-8W83P" '
g_objKeyDictionaryWin8.Add "ServerMultiPointStandard", "HM7DN-YVMH3-46JC3-XYTG7-CYQJJ" '
g_objKeyDictionaryWin8.Add "ServerMultiPointPremium", "XNH6W-2V9GX-RGJ4K-Y8X6F-QGJ2G" '
g_objKeyDictionaryWin8.Add "ServerStandard", "XC9B7-NBPP2-83J2H-RHMBY-92BT4" '
g_objKeyDictionaryWin8.Add "ServerStandardCore", "XC9B7-NBPP2-83J2H-RHMBY-92BT4" '
' Windows 8.1 & Windows server 2012 R2
g_objKeyDictionaryWin8R2.Add "CoreARM", "XYTND-K6QKT-K2MRH-66RTM-43JKP"
g_objKeyDictionaryWin8R2.Add "ServerStandard", "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"
g_objKeyDictionaryWin8R2.Add "ServerCloudStorageCore", "3NPTF-33KPT-GGBPR-YX76B-39KDD"
g_objKeyDictionaryWin8R2.Add "ServerCloudStorage", "3NPTF-33KPT-GGBPR-YX76B-39KDD"
g_objKeyDictionaryWin8R2.Add "EmbeddedIndustryA", "VHXM3-NR6FT-RY6RT-CK882-KW2CJ"
g_objKeyDictionaryWin8R2.Add "CoreN", "7B9N3-D94CG-YTVHR-QBPX3-RJP64"
g_objKeyDictionaryWin8R2.Add "CoreSingleLanguage", "BB6NG-PQ82V-VRDPW-8XVD2-V8P66"
g_objKeyDictionaryWin8R2.Add "ServerDatacenterCore", "W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9"
g_objKeyDictionaryWin8R2.Add "Professional", "GCRJD-8NW9H-F2CDX-CCM8D-9D6T9"
g_objKeyDictionaryWin8R2.Add "ServerSolutionCore", "KNC87-3J2TX-XB4WP-VCPJV-M4FWM"
g_objKeyDictionaryWin8R2.Add "ServerSolution", "KNC87-3J2TX-XB4WP-VCPJV-M4FWM"
g_objKeyDictionaryWin8R2.Add "EmbeddedIndustryE", "FNFKF-PWTVT-9RC8H-32HB2-JB34X"
g_objKeyDictionaryWin8R2.Add "ProfessionalN", "HMCNV-VVBFX-7HMBH-CTY9B-B4FXY"
g_objKeyDictionaryWin8R2.Add "EmbeddedIndustry", "NMMPB-38DD4-R2823-62W8D-VXKJB"
g_objKeyDictionaryWin8R2.Add "CoreCountrySpecific", "NCTT7-2RGK8-WMHRF-RY7YQ-JTXG3"
g_objKeyDictionaryWin8R2.Add "ProfessionalWMC", "789NJ-TQK6T-6XTH8-J39CJ-J8D3P"
g_objKeyDictionaryWin8R2.Add "ServerDatacenter", "W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9"
g_objKeyDictionaryWin8R2.Add "ServerStandardCore", "D2N9P-3P6X9-2R39C-7RTCD-MDVJX"
g_objKeyDictionaryWin8R2.Add "Enterprise", "MHF9N-XY6XB-WVXMC-BTDCT-MKKG7"
g_objKeyDictionaryWin8R2.Add "Core", "M9Q9P-WNJJT-6PXPY-DWX8H-6XWKK"
g_objKeyDictionaryWin8R2.Add "EnterpriseN", "TT4HM-HN7YT-62K67-RGRQJ-JFFXW"
' Windows 10 & Windows Server 2016
g_objKeyDictionaryWin10.Add "Professional", "W269N-WFGWX-YVC9B-4J6C9-T83GX"
g_objKeyDictionaryWin10.Add "ProfessionalN", "MH37W-N47XK-V7XM9-C7227-GCQG9"
g_objKeyDictionaryWin10.Add "Enterprise", "NPPR9-FWDCX-D2C8J-H872K-2YT43"
g_objKeyDictionaryWin10.Add "EnterpriseN", "DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4"
g_objKeyDictionaryWin10.Add "ServerSolutionCore", "JCKRF-N37P4-C2D82-9YXRT-4M63B"
g_objKeyDictionaryWin10.Add "ServerAzureCor", "VP34G-4NPPG-79JTQ-864T4-R3MQX"
g_objKeyDictionaryWin10.Add "ServerSolution", "JCKRF-N37P4-C2D82-9YXRT-4M63B"
g_objKeyDictionaryWin10.Add "ServerStandard", "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"
g_objKeyDictionaryWin10.Add "ServerCloudStorage", "QN4C6-GBJD2-FB422-GHWJK-GJG2R"
g_objKeyDictionaryWin10.Add "ServerCloudStorageCore", "QN4C6-GBJD2-FB422-GHWJK-GJG2R"
g_objKeyDictionaryWin10.Add "ServerDatacenterCore", "CB7KF-BWN84-R7R2Y-793K2-8XDDG"
g_objKeyDictionaryWin10.Add "ServerDatacenter", "CB7KF-BWN84-R7R2Y-793K2-8XDDG"
g_objKeyDictionaryWin10.Add "ServerStandardCore", "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY"
g_objKeyDictionaryWin10.Add "ServerAzureCorCore", "VP34G-4NPPG-79JTQ-864T4-R3MQX"
' These can be activated by AVMA. https://technet.microsoft.com/en-us/library/dn303421.aspx
' AVMA based activation is used by Azure Stack
g_objKeyDictionaryServer2012R2AVMA.Add "ServerDatacenterCore", "Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW"
g_objKeyDictionaryServer2012R2AVMA.Add "ServerDatacenter", "Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW"
g_objKeyDictionaryServer2012R2AVMA.Add "ServerStandardCore", "DBGBW-NPF86-BJVTX-K3WKJ-MTB6V"
g_objKeyDictionaryServer2012R2AVMA.Add "ServerStandard", "DBGBW-NPF86-BJVTX-K3WKJ-MTB6V"
g_objKeyDictionaryServer2012R2AVMA.Add "ServerSolutionCore", "K2XGM-NMBT3-2R6Q8-WF2FK-P36R2"
g_objKeyDictionaryServer2012R2AVMA.Add "ServerSolution", "K2XGM-NMBT3-2R6Q8-WF2FK-P36R2"
g_objKeyDictionaryServer2016AVMA.Add "ServerDatacenterCore", "TMJ3Y-NTRTM-FJYXT-T22BY-CWG3J"
g_objKeyDictionaryServer2016AVMA.Add "ServerDatacenter", "TMJ3Y-NTRTM-FJYXT-T22BY-CWG3J"
g_objKeyDictionaryServer2016AVMA.Add "ServerStandardCore", "C3RCX-M6NRP-6CXC9-TW2F2-4RHYD"
g_objKeyDictionaryServer2016AVMA.Add "ServerStandard", "C3RCX-M6NRP-6CXC9-TW2F2-4RHYD"
g_objKeyDictionaryServer2016AVMA.Add "ServerSolutionCore", "B4YNW-62DX9-W8V6M-82649-MHBKQ"
g_objKeyDictionaryServer2016AVMA.Add "ServerSolution", "B4YNW-62DX9-W8V6M-82649-MHBKQ"
g_objKeyDictionaryServer2019AVMA.Add "ServerDatacenterCore", "H3RNG-8C32Q-Q8FRX-6TDXV-WMBMW"
g_objKeyDictionaryServer2019AVMA.Add "ServerDatacenter", "H3RNG-8C32Q-Q8FRX-6TDXV-WMBMW"
g_objKeyDictionaryServer2019AVMA.Add "ServerDatacenterACor", "H3RNG-8C32Q-Q8FRX-6TDXV-WMBMW"
g_objKeyDictionaryServer2019AVMA.Add "ServerStandardCore", "TNK62-RXVTB-4P47B-2D623-4GF74"
g_objKeyDictionaryServer2019AVMA.Add "ServerStandard", "TNK62-RXVTB-4P47B-2D623-4GF74"
g_objKeyDictionaryServer2019AVMA.Add "ServerSolutionCore", "2CTP7-NHT64-BP62M-FV6GG-HFV28"
g_objKeyDictionaryServer2019AVMA.Add "ServerSolution", "2CTP7-NHT64-BP62M-FV6GG-HFV28"
g_objKeyDictionaryServer2022AVMA.Add "ServerDatacenterCore", "W3GNR-8DDXR-2TFRP-H8P33-DV9BG"
g_objKeyDictionaryServer2022AVMA.Add "ServerDatacenter", "W3GNR-8DDXR-2TFRP-H8P33-DV9BG"
g_objKeyDictionaryServer2022AVMA.Add "ServerStandardCore", "YDFWN-MJ9JR-3DYRK-FXXRW-78VHK"
g_objKeyDictionaryServer2022AVMA.Add "ServerStandard", "YDFWN-MJ9JR-3DYRK-FXXRW-78VHK"
' Windows Server 2019 / RS5
g_objKeyDictionary2019.Add "ServerDatacenterACorCore", "6NMRW-2C8FM-D24W7-TQWMY-CWH2D"
g_objKeyDictionary2019.Add "ProfessionalWorkstationN", "9FNHH-K3HBT-3W4TD-6383H-6XYWF"
g_objKeyDictionary2019.Add "ServerAzureCor", "FDNH6-VW9RW-BXPJ7-4XTYG-239TB"
g_objKeyDictionary2019.Add "ServerRdshCore", "CPWHC-NT2C7-VYW78-DHDB2-PG3GK"
g_objKeyDictionary2019.Add "ServerArm64", "GRFBW-QNDC4-6QBHG-CCK3B-2PR88"
g_objKeyDictionary2019.Add "ServerStandardACorCore", "N2KJX-J94YW-TQVFB-DG9YT-724CC"
g_objKeyDictionary2019.Add "ProfessionalEducation", "6TP4R-GNPTD-KYYHQ-7B7DP-J447Y"
g_objKeyDictionary2019.Add "Cloude", "NBTWJ-3DR69-3C4V8-C26MC-GQ9M6"
g_objKeyDictionary2019.Add "EducationN", "2WH4N-8QGBV-H22JP-CT43Q-MDWWJ"
g_objKeyDictionary2019.Add "ServerSolutionCore", "WVDHN-86M7X-466P6-VHXV7-YY726"
g_objKeyDictionary2019.Add "ProfessionalEducationN", "YVWGF-BXNMC-HTQYQ-CPQ99-66QFC"
g_objKeyDictionary2019.Add "ProfessionalWorkstation", "NRG8B-VKK3Q-CXVCJ-9G2XF-6Q84J"
g_objKeyDictionary2019.Add "EnterpriseS", "M7XTQ-FN8P6-TTKYV-9D4CC-J462D"
g_objKeyDictionary2019.Add "EnterpriseG", "YYVX9-NTFWV-6MDM3-9PT4T-4M68B"
g_objKeyDictionary2019.Add "ServerAzureCorCore", "FDNH6-VW9RW-BXPJ7-4XTYG-239TB"
g_objKeyDictionary2019.Add "ServerDatacenterCore", "WMDGN-G9PQG-XVVXX-R3X43-63DFG"
g_objKeyDictionary2019.Add "CoreSingleLanguage", "7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH"
g_objKeyDictionary2019.Add "Core", "TX9XD-98N7V-6WMQ6-BX7FG-H8Q99"
g_objKeyDictionary2019.Add "Education", "NW6C2-QMPVW-D7KKK-3GKT6-VCFB2"
g_objKeyDictionary2019.Add "ServerArm64Core", "GRFBW-QNDC4-6QBHG-CCK3B-2PR88"
g_objKeyDictionary2019.Add "CoreN", "3KHY7-WNT83-DGQKR-F7HPR-844BM"
g_objKeyDictionary2019.Add "Professional", "W269N-WFGWX-YVC9B-4J6C9-T83GX"
g_objKeyDictionary2019.Add "ProfessionalN", "MH37W-N47XK-V7XM9-C7227-GCQG9"
g_objKeyDictionary2019.Add "ServerDatacenterACor", "6NMRW-2C8FM-D24W7-TQWMY-CWH2D"
g_objKeyDictionary2019.Add "Enterprise", "NPPR9-FWDCX-D2C8J-H872K-2YT43"
g_objKeyDictionary2019.Add "EnterpriseSN", "92NFX-8DJQP-P6BBQ-THF9C-7CG2H"
g_objKeyDictionary2019.Add "ServerDatacenter", "WMDGN-G9PQG-XVVXX-R3X43-63DFG"
g_objKeyDictionary2019.Add "ServerStandardACor", "N2KJX-J94YW-TQVFB-DG9YT-724CC"
g_objKeyDictionary2019.Add "CoreCountrySpecific", "PVMJN-6DFY6-9CCP6-7BKTT-D3WVR"
g_objKeyDictionary2019.Add "EnterpriseN", "DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4"
g_objKeyDictionary2019.Add "EnterpriseGN", "44RPN-FTY23-9VTTB-MP9BX-T84FV"
g_objKeyDictionary2019.Add "ServerRdsh", "CPWHC-NT2C7-VYW78-DHDB2-PG3GK"
g_objKeyDictionary2019.Add "ServerStandardCore", "N69G4-B89J2-4G8F4-WWYCC-J464C"
g_objKeyDictionary2019.Add "ServerSolution", "WVDHN-86M7X-466P6-VHXV7-YY726"
g_objKeyDictionary2019.Add "ServerStandard", "N69G4-B89J2-4G8F4-WWYCC-J464C"
Sub Initialize()
Dim os
Set g_Trace = GetScriptObject(Me.WScript, "Tracing.wsf", "TraceSource")
g_Trace.Name = "SoftwareLicensing"
Set os = GetScriptObject(Me.WScript, "OperatingSystem.wsf", "OperatingSystem")
Set os.WScript = Me.WScript
os.Initialize
g_OSBuildNumber = GetOSCurrentBuildNumber
End Sub
Sub ConfigureLicensing(keyManagementServiceHostname, useAVMA)
If IsEval() Then
' don't reconfigure an evaluation copy
Set oTraceEvent = g_Trace.CreateEvent("INFO")
With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("LicensingRemediation"))
With .appendChild(oTraceEvent.ownerDocument.createElement("EvaluationProduct"))
End With
End With
g_Trace.TraceEvent oTraceEvent
Exit Sub
End If
ActivateKmsClientProduct useAVMA
If (useAVMA = False) Then
ConfigureKmsClient keyManagementServiceHostname
End If
Set oResults = ExecuteAndTraceWithResults("%SystemRoot%\OEM\WaGuest.exe /refreshlicense " & WindowsAppId, g_Trace)
If oResults.ExitCode <> 0 Then
Err.Raise vbObjectError + 6, "Licensing.wsf", "Failed to refresh license status"
Exit Sub
End If
End Sub
Sub ActivateKmsClientProduct(useAVMA)
Dim colProducts, objProduct, sProductKey, objDictionary, buildNumber
Dim kvp_pa_licensing : kvp_pa_licensing = "oobeSystem_PA_Licensing"
If IsEmpty(g_OSBuildNumber) or IsNull(g_OSBuildNumber) or g_OSBuildNumber = "" Then
Err.Raise vbObjectError + 5, "Licensing.wsf", "Failed to get current OS build number, cannot apply licensing"
Exit Sub
End If
' Windows has a number of licensed "products" within it, as exposed by the SPP subsystem.
' This routine selects the product associated with the "VL" channel.
'
' Vocabulary:
' * Build Number - the build number of a Windows image.
' * AVMA - automatic virtual machine activation is used in Azure Stack, See
' https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn303421(v=ws.11)
' * KMS - key management services is used in conjuction with GVLKs to activate Windows OS
' products.
' * GLVK - gross volume license keys are public keys used in combination with a KMS to
' activate a Windows OS product.
'
' See https://msdn.microsoft.com/en-us/library/ee957718(v=vs.85).aspx for details on
' the names below.
'
' * PartialProductKey - 5x5 key, which represents a portion of the key. A non-blank
' partial product key indicates that this product is the one to be licensed.
' * ID - product identifier.
' * LicenseFamily - group identifier for the SKU used to determine license relationships
' for add-ons, e.g. Professional or Education
' * Description - product description, this is a human-readable form of ID and LicenseFamily.
'
' > GetProductCollection() - returns a list of *Windows* products. An image may contain
' multiple editions. (This is typical for Client, but not yet in Server.) The correct edition
' is determined by observing that if PartialProductKey is not null, that this is the correct
' edition to license.
'
' > IsKmsClient() - at this time Azure only attempts to license products that are KMS. This may
' change in the future.
'
' > If buildNumber >= ##### - MSDN provides a list of GVLKs that are installed as part of
' product and edition. Because the keys are public, the customer (read Azure) must have a KMS
' to allow the activation to happen. The keys change as new builds are produced. Azure
' supports (for activation) as far as back 2008 / Windows 7.
'
' > if useAVMA = True ... - Azure Stack supports AVMA, and this code is explicitly in place for
' Azure Stack. If a key cannot be found based on the license family, the code falls back to KMS
' activiation.
GetProductCollection()
' We only care that it is a KMS client if we are using KMS,
' otherwise we default to AVMA keys
If useAVMA = True or IsKmsClient(g_objLicense.Description) Then
buildNumber = CInt(g_OSBuildNumber)
If useAVMA = False Then
' this is also the current product, so no reconfiguration is necessary
Set oTraceEvent = g_Trace.CreateEvent("INFO")
With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("LicensingRemediation"))
With .appendChild(oTraceEvent.ownerDocument.createElement("CurrentProduct"))
.setAttribute "id", g_objLicense.ProductId
.setAttribute "licenseFamily", g_objLicense.Family
.setAttribute "partialProductKey", g_objLicense.PartialKey
With .appendChild(oTraceEvent.ownerDocument.createElement("Description"))
.Text = g_objLicense.Description
End With
End With
End With
g_Trace.TraceEvent oTraceEvent
Exit Sub
End If
If buildNumber >= 20348 Then
' Server 2022 supports AVMA
If g_objKeyDictionaryServer2022AVMA.Exists(g_objLicense.Family) = True Then
Set objDictionary = g_objKeyDictionaryServer2022AVMA
End If
ElseIf buildNumber >= 17733 Then
' Server 2019 / RS5
If g_objKeyDictionaryServer2019AVMA.Exists(g_objLicense.Family) = True Then
Set objDictionary = g_objKeyDictionaryServer2019AVMA
End If
ElseIf buildNumber >= 14393 Then
' Server 2016 build which supports AVMA
If g_objKeyDictionaryServer2016AVMA.Exists(g_objLicense.Family) = True Then
Set objDictionary = g_objKeyDictionaryServer2016AVMA
End If
ElseIf buildNumber >= 10240 Then
' Windows 10 / Server 2016 that is not AVMA-capable
ElseIf buildNumber >= 9600 Then
' Windows 8.1 / Server 2012 R2
If g_objKeyDictionaryServer2012R2AVMA.Exists(g_objLicense.Family) = True Then
Set objDictionary = g_objKeyDictionaryServer2012R2AVMA
End If
End If
If Not objDictionary.Exists(g_objLicense.Family) Then
Err.Raise vbObjectError + 2, "Licensing.wsf", "Unsupported license family (" & g_objLicense.Family & " BuildNumber " & buildNumber & ")"
Exit Sub
End If
sProductKey = objDictionary.Item(g_objLicense.Family)
On Error Resume Next
Set oResults = ExecuteAndTraceWithResults("%SystemRoot%\OEM\WaGuest.exe /installproductkey " & sProductKey, g_Trace)
If oResults.ExitCode <> 0 Then
Err.Raise vbObjectError + 3, "Licensing.wsf", "Failed to install product key (" & Err.Number & ")"
Exit Sub
End If
On Error Goto 0
Set oTraceEvent = g_Trace.CreateEvent("INFO")
With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("LicensingRemediation"))
With .appendChild(oTraceEvent.ownerDocument.createElement("InstalledProduct"))
.setAttribute "id", g_objLicense.ProductId
.setAttribute "licenseFamily", g_objLicense.Family
.setAttribute "productKey", sProductKey
.setAttribute "partialProductKey", g_objLicense.PartialKey
.setAttribute "buildNumber", buildNumber
.setAttribute "useAVMA", useAVMA
With .appendChild(oTraceEvent.ownerDocument.createElement("Description"))
.Text = g_objLicense.Description
End With
End With
End With
g_Trace.TraceEvent oTraceEvent
SetKvpRegistry kvp_pa_licensing, g_objLicense.ProductId & ";" & g_objLicense.Family & ";" & sProductKey & ";" & g_objLicense.PartialKey & ";" & buildNumber & ";" & useAVMA & ";" & g_objLicense.Description, g_Trace
Exit Sub
End If
' no products matched
Err.Raise vbObjectError + 4, "Licensing.wsf", "Could not find the VOLUME_KMSCLIENT product"
End Sub
Sub ConfigureKmsClient(keyManagementServiceHostname)
Const keyManagementServicePath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
If IsNull(keyManagementServiceHostname) or IsEmpty(keyManagementServiceHostname) or keyManagementServiceHostname = "" Then keyManagementServiceHostname = "kms.core.windows.net"
SetRegistryValue g_Trace, _
keyManagementServicePath, _
"KeyManagementServiceName", _
"REG_SZ", _
keyManagementServiceHostname, False
SetRegistryValue g_Trace, _
keyManagementServicePath, _
"KeyManagementServicePort", _
"REG_SZ", _
KeyManagementServicePort, False
End Sub
Private Function IsEval()
Dim colProducts, objProduct, iIsPrimaryWindowsSku, sProductKey
GetProductCollection()
If IsEvalClient(g_objLicense.Description) Or g_objLicense.HasEvaluationEndDate = "true" Then
IsEval = True
Else
IsEval = False
End If
Exit Function
End Function
Private Function IsKmsClient(strDescription)
If InStr(strDescription, "VOLUME_KMSCLIENT") > 0 Then
IsKmsClient = True
Else
IsKmsClient = False
End If
End Function
Private Function IsEvalClient(strDescription)
If InStr(strDescription, "TIMEBASED_EVAL") > 0 Then
IsEvalClient = True
Else
IsEvalClient = False
End If
End Function
Private Function GetProductCollection()
If g_objLicense Is Nothing Then
Dim oResults, arr
Set oResults = ExecuteAndTraceWithResults("%SystemRoot%\OEM\WaGuest.exe /getproductcollection " & WindowsAppId, g_Trace)
' Expected output is:
' <ProductId>
' <PartialKey>
' <LicenseFamily>
' <Description>
' <EvaluationEndDate>
' <Name>
If oResults.ExitCode <> 0 Then
Err.Raise vbObjectError + 7, "Licensing.wsf", "Failed to get product collection (" & oResults.StdErr & ")"
Exit Function
End If
arr = Split(oResults.StdOut, vbNewLine)
If UBound(arr) <> 5 Then
Err.Raise vbObjectError + 8, "Licensing.wsf", "getproductcollection returns wrong number of info (" & UBound(arr) & ")"
Exit Function
End If
Set g_objLicense = New License
g_objLicense.ProductId = arr(0)
g_objLicense.PartialKey = arr(1)
g_objLicense.Family = arr(2)
g_objLicense.Description = arr(3)
g_objLicense.HasEvaluationEndDate = arr(4)
g_objLicense.Name = arr(5)
End If
End Function
</script>
</component>
</package>