private const L_optReinstallLicensesUsage = "Re-install system license files"
private const L_optDisplayIID = "dti"
private const L_optDisplayIIDUsage = "Display Installation ID for offline activation"
private const L_optPhoneActivateProduct = "atp"
private const L_optPhoneActivateProductUsage = "Activate product with user-provided Confirmation ID"
private const L_optReArmWindows = "rearm"
private const L_optReArmWindowsUsage = "Reset the licensing status of the machine"
'KMS options
private const L_optSetKmsName = "skms"
private const L_optSetKmsNameUsage = "Set the name and/or the port for the KMS computer this machine will use"
private const L_optClearKmsName = "ckms"
private const L_optClearKmsNameUsage = "Clear name of KMS computer used (sets the port to the default)"
private const L_optSetActivationInterval = "sai"
private const L_optSetActivationIntervalUsage = "Set interval (minutes) for unactivated clients to attempt KMS connection. The activation interval must be between 15 minutes (min) and 30 days (max) although the default (2 hours) is recommended."
private const L_optSetRenewalInterval = "sri"
private const L_optSetRenewalIntervalUsage = "Set renewal interval (minutes) for activated clients to attempt KMS connection. The renewal interval must be between 15 minutes (min) and 30 days (max) although the default (7 days) is recommended."
private const L_optSetKmsListenPort = "sprt"
private const L_optSetKmsListenPortUsage = "Set TCP port KMS will use to communicate with clients"
private const L_optSetDNS = "sdns"
private const L_optSetDNSUsage = "Enable DNS publishing by KMS (default)"
private const L_optClearDNS = "cdns"
private const L_optClearDNSUsage = "Disable DNS publishing by KMS"
private const L_optSetNormalPriority = "spri"
private const L_optSetNormalPriorityUsage = "Set KMS priority to normal (default)"
private const L_optClearNormalPriority = "cpri"
private const L_optClearNormalPriorityUsage = "Set KMS priority to low"
private const L_MsgPhoneNumbers = "Product activation telephone numbers can be obtained by searching the phone.inf file for the appropriate phone number for your location/country. You can open the phone.inf file from a Command Prompt or the Start Menu by running: notepad %systemroot%\system32\slui\phone.inf"
private const L_MsgErrorText_10 = "The maximum allowed number of re-arms has been exceeded. You must re-install the OS before trying to re-arm again."
private const L_MsgErrorText_11 = "The machine is running within the non-genuine grace period. Please run 'slui.exe 0x31' to go online and make the machine genuine."
private const L_MsgErrorText_12 = "Windows is running within the non-genuine notification period. Please run 'slui.exe 0x31' to go online and validate Windows."
private const L_MsgInvalidDataError = "Error: The data is invalid"
private const L_MsgUndeterminedPrimaryKey = "Warning: SLMGR was not able to validate the current product key for Windows. Please upgrade to the latest service pack."
private const L_MsgUndeterminedPrimaryKeyOperation = "Warning: This operation may affect more than one target license. Please verify the results."
private const L_MsgUndeterminedOperationFormat = "Processing the license for %PRODUCTDESCRIPTION% (%PRODUCTID%)."
private const L_MsgKmsCumulativeRequestsFromClients = "Key Management Service cumulative requests received from clients"
Private Function ParseCommandLine(bShowKmsInfo, bShowKmsClientInfo, index)
Dim strOption, chOpt
ParseCommandLine = intKnownOption
strOption = LCase(WScript.Arguments.Item(index))
chOpt = Left(strOption, 1)
If (chOpt <> "-") And (chOpt <> "/") Then
ParseCommandLine = intUnknownOption
Exit Function
End If
strOption = Right(strOption, Len(strOption) - 1)
If strOption = GetResource("L_optInstallLicense") Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optInstallLicense"), GetResource("L_ParamsLicenseFile")) Then
InstallLicense WScript.Arguments.Item(index+1)
End If
ElseIf strOption = GetResource("L_optInstallProductKey") Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optInstallProductKey"), GetResource("L_ParamsProductKey")) Then
InstallProductKey WScript.Arguments.Item(index+1)
End If
ElseIf strOption = GetResource("L_optUninstallProductKey") Then
UninstallProductKey
ElseIf (strOption = GetResource("L_optDisplayIID") And bShowKmsClientInfo = False) Then
DisplayIID
ElseIf strOption = GetResource("L_optActivateProduct") Then
ActivateProduct
ElseIf (strOption = GetResource("L_optPhoneActivateProduct") And bShowKmsClientInfo = False) Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optPhoneActivateProduct"), GetResource("L_ParamsPhoneActivate")) Then
ElseIf strOption = GetResource("L_optClearPKeyFromRegistry") Then
ClearPKeyFromRegistry
ElseIf strOption = GetResource("L_optReinstallLicenses") Then
ReinstallLicenses
ElseIf strOption = GetResource("L_optReArmWindows") Then
ReArmWindows()
ElseIf strOption = GetResource("L_optExpirationDatime") Then
ExpirationDatime()
ElseIf (strOption = GetResource("L_optSetKmsName") And bShowKmsClientInfo = True) Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optSetKmsName"), GetResource("L_ParamsSetKms")) Then
SetKmsMachineName WScript.Arguments.Item(index+1)
End If
ElseIf (strOption = GetResource("L_optClearKmsName") And bShowKmsClientInfo = True) Then
ClearKms
ElseIf (strOption = GetResource("L_optSetActivationInterval") And bShowKmsInfo = True) Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optSetActivationInterval"), GetResource("L_ParamsSetActivationInterval")) Then
ElseIf (strOption = GetResource("L_optSetRenewalInterval") And bShowKmsInfo = True) Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optSetRenewalInterval"), GetResource("L_ParamsSetRenewalInterval")) Then
ElseIf (strOption = GetResource("L_optSetKmsListenPort") And bShowKmsInfo = True) Then
If HandleOptionParam(bShowKmsInfo, bShowKmsClientInfo, index+1, True, GetResource("L_optSetKmsListenPort"), GetResource("L_ParamsSetKmsListenPort")) Then
SetKmsListenPort WScript.Arguments.Item(index+1)
End If
ElseIf (strOption = GetResource("L_optSetDNS") And bShowKmsInfo = True) Then
SetDnsPublishingDisabled(False)
ElseIf (strOption = GetResource("L_optClearDNS") And bShowKmsInfo = True) Then
SetDnsPublishingDisabled(True)
ElseIf (strOption = GetResource("L_optSetNormalPriority") And bShowKmsInfo = True) Then
SetKmsLowPriority(False)
ElseIf (strOption = GetResource("L_optClearNormalPriority") And bShowKmsInfo = True) Then
SetKmsLowPriority(True)
Else
ParseCommandLine = intUnknownOption
End If
End Function
' global options
Private Sub UninstallProductKey()
Dim objProduct
Dim lRet
Dim iIsPrimaryWindowsSku, bAtLeastOnKeyUninstalled
' Clear the KMS version from the registry (both 64 and 32 bit locations)
If InStr(strDescription, "VOLUME_KMSCLIENT") > 0 Then
IsKmsClient = True
Else
IsKmsClient = False
End If
End Function
Private Function IsKmsServer(strDescription)
If IsKmsClient(strDescription) Then
IsKmsServer = False
Else
If InStr(strDescription, "VOLUME_KMS") > 0 Then
IsKmsServer = True
Else
IsKmsServer = False
End If
End If
End Function
'Returns 0 if this is not the primary SKU, 1 if it is, and 2 if we aren't certain (older clients)
Function GetIsPrimaryWindowsSKU(objProduct)
Dim iPrimarySku
Dim bIsAddOn
'Assume this is not the primary SKU
iPrimarySku = 0
'Verify the license is for Windows, that it has a partial key, and that
If (LCase(objProduct.ApplicationId) = WindowsAppId And objProduct.PartialProductKey <> "") Then
'If we can get verify the AddOn property then we can be certain
On Error Resume Next
bIsAddOn = objProduct.LicenseIsAddon
If Err.Number = 0 Then
If bIsAddOn = true Then
iPrimarySku = 0
Else
iPrimarySku = 1
End If
Else
'If we can not get the AddOn property then we assume this is a previous version
'and we return a value of Uncertain, unless we can prove otherwise
If (IsKmsClient(objProduct.Description) Or IsKmsServer(objProduct.Description)) Then
'If the description is KMS related, we can be certain that this is a primary SKU
iPrimarySku = 1
Else
'Indeterminate since the property was missing and we can't verify KMS
iPrimarySku = 2
End If
End If
End If
GetIsPrimaryWindowsSKU = iPrimarySku
End Function
Private Function WasPrimaryKeyFound(strPrimarySkuType)
If (IsKmsServer(strPrimarySkuType) Or IsKmsClient(strPrimarySkuType) Or (InStr(strPrimarySkuType, NonKMSPrimaryKey) > 0) Or (InStr(strPrimarySkuType, IndeterminatePrimaryKeyFound) > 0)) Then
WasPrimaryKeyFound = True
Else
WasPrimaryKeyFound = False
End If
End Function
Private Function CanPrimaryKeyTypeBeDetermined(strPrimarySkuType)
If ((InStr(strPrimarySkuType, IndeterminatePrimaryKeyFound) > 0) Or (InStr(strPrimarySkuType, NoPrimaryKeyFound) > 0)) Then
CanPrimaryKeyTypeBeDetermined = False
Else
CanPrimaryKeyTypeBeDetermined = True
End If
End Function
Private Function GetPrimarySKUType()
Dim objService, objProduct
Dim strPrimarySKUType, strDescription
Dim iIsPrimaryWindowsSku
For Each objService in g_objWMIService.InstancesOf(ServiceClass)
For Each objProduct in g_objWMIService.InstancesOf(ProductClass)