Static | ZeroBOX
No static analysis available.
' Copyright (c) Microsoft Corporation. All rights reserved.
' Windows Software Licensing Management Tool.
' Script Name: slmgr.vbs
Dim g_objWMIService, g_strComputer, g_strUserName, g_strPassword, g_IsRemoteComputer
g_strComputer = "."
g_IsRemoteComputer = False
dim g_EchoString
g_EchoString = ""
dim g_objRegistry
Dim g_resourceDictionary, g_resourcesLoaded
Set g_resourceDictionary = CreateObject("Scripting.Dictionary")
g_resourcesLoaded = False
Dim g_DeterminedDisplayFlags
g_DeterminedDisplayFlags = False
Dim g_ShowKmsInfo
Dim g_ShowKmsClientInfo
Dim g_ShowTkaClientInfo
Dim g_ShowTBLInfo
Dim g_ShowPhoneInfo
g_ShowKmsInfo = False
g_ShowKmsClientInfo = false
g_ShowTBLInfo = False
g_ShowPhoneInfo = False
Private Sub DisplayUsage ()
LineOut findar("L_MsgHelp_1")
LineOut findar("L_MsgHelp_2")
LineOut " " & findar("L_MsgHelp_3")
LineOut " " & findar("L_MsgHelp_4")
LineOut " " & findar("L_MsgHelp_5")
LineOut ""
LineOut findar("L_MsgGlobalOptions")
OptLine findar("L_optInstallProductKey"), findar("L_ParamsProductKey"), findar("L_optInstallProductKeyUsage")
OptLine findar("L_optActivateProduct"), findar("L_ParamsActivationIDOptional"), findar("L_optActivateProductUsage")
OptLine findar("L_optDisplayInformation"), findar("L_ParamsActIDOptional"), findar("L_optDisplayInformationUsage")
OptLine findar("L_optDisplayInformationVerbose"), findar("L_ParamsActIDOptional"), findar("L_optDisplayInformationUsageVerbose")
OptLine findar("L_optExpirationDatime"), findar("L_ParamsActivationIDOptional"), findar("L_optExpirationDatimeUsage")
LineFlush ""
LineOut findar("L_MsgAdvancedOptions")
OptLine findar("L_optClearPKeyFromRegistry"), "", findar("L_optClearPKeyFromRegistryUsage")
OptLine findar("L_optInstallLicense"), findar("L_ParamsLicenseFile"), findar("L_optInstallLicenseUsage")
OptLine findar("L_optReinstallLicenses"), "", findar("L_optReinstallLicensesUsage")
OptLine findar("L_optReArmWindows"), "", findar("L_optReArmWindowsUsage")
OptLine findar("L_optReArmApplication"), findar("L_ParamsApplicationID"), findar("L_optReArmApplicationUsage")
OptLine findar("L_optReArmSku"), findar("L_ParamsActivationID"), findar("L_optReArmSkuUsage")
OptLine findar("L_optUninstallProductKey"), findar("L_ParamsActivationIDOptional"), findar("L_optUninstallProductKeyUsage")
LineOut ""
OptLine findar("L_optDisplayIID"), findar("L_ParamsActivationIDOptional"), findar("L_optDisplayIIDUsage")
OptLine2 findar("L_optPhoneActivateProduct"), findar("L_ParamsPhoneActivate"), findar("L_ParamsActivationIDOptional"), findar("L_optPhoneActivateProductUsage")
LineOut ""
LineOut findar("L_MsgKmsClientOptions")
OptLine2 findar("L_optSetKmsName"), findar("L_ParamsSetKms"), findar("L_ParamsActivationIDOptional"), findar("L_optSetKmsNameUsage")
OptLine findar("L_optClearKmsName"), findar("L_ParamsActivationIDOptional"), findar("L_optClearKmsNameUsage")
OptLine2 findar("L_optSetKmsLookupDomain"), findar("L_ParamsSetKmsLookupDomain"), findar("L_ParamsActivationIDOptional"), findar("L_optSetKmsLookupDomainUsage")
OptLine findar("L_optClearKmsLookupDomain"), findar("L_ParamsActivationIDOptional"), findar("L_optClearKmsLookupDomainUsage")
OptLine findar("L_optSetKmsHostCaching"), "", findar("L_optSetKmsHostCachingUsage")
OptLine findar("L_optClearKmsHostCaching"), "", findar("L_optClearKmsHostCachingUsage")
LineFlush ""
LineOut findar("L_MsgTkaClientOptions")
OptLine findar("L_optListInstalledILs"), "", findar("L_optListInstalledILsUsage")
OptLine findar("L_optRemoveInstalledIL"), findar("L_ParamsRemoveInstalledIL"), findar("L_optRemoveInstalledILUsage")
OptLine findar("L_optListTkaCerts"), "", findar("L_optListTkaCertsUsage")
OptLine findar("L_optForceTkaActivation"), findar("L_ParamsForceTkaActivation"), findar("L_optForceTkaActivationUsage")
LineFlush ""
LineOut findar("L_MsgKmsOptions")
OptLine findar("L_optSetKmsListenPort"), findar("L_ParamsSetListenKmsPort"), findar("L_optSetKmsListenPortUsage")
OptLine findar("L_optSetActivationInterval"), findar("L_ParamsSetActivationInterval"), findar("L_optSetActivationIntervalUsage")
OptLine findar("L_optSetRenewalInterval"), findar("L_ParamsSetRenewalInterval"), findar("L_optSetRenewalIntervalUsage")
OptLine findar("L_optSetDNS"), "", findar("L_optSetDNSUsage")
OptLine findar("L_optClearDNS"), "", findar("L_optClearDNSUsage")
OptLine findar("L_optSetNormalPriority"), "", findar("L_optSetNormalPriorityUsage")
OptLine findar("L_optClearNormalPriority"), "", findar("L_optClearNormalPriorityUsage")
OptLine2 findar("L_optSetVLActivationType"), findar("L_ParamsVLActivationTypeOptional"), findar("L_ParamsActivationIDOptional"), findar("L_optSetVLActivationTypeUsage")
LineFlush ""
LineOut findar("L_MsgADOptions")
OptLine2 findar("L_optADActivate"), findar("L_ParamsProductKey"), findar("L_ParamsAONameOptional"), findar("L_optADActivateUsage")
OptLine findar("L_optADGetIID"), findar("L_ParamsProductKey"), findar("L_optADGetIIDUsage")
OptLine3 findar("L_optADApplyCID"), findar("L_ParamsProductKey"), findar("L_ParamsPhoneActivate"), findar("L_ParamsAONameOptional"), findar("L_optADApplyCIDUsage")
OptLine findar("L_optADListAOs"), "", findar("L_optADListAOsUsage")
OptLine findar("L_optADDeleteAO"), findar("L_ParamsAODistinguishedName"), findar("L_optADDeleteAOsUsage")
ExitScript 1
End Sub
Private Sub OptLine(strOption, strParams, strUsage)
LineOut "/" & strOption & " " & strParams
LineOut " " & strUsage
End Sub
Private Sub OptLine2(strOption, strParam1, strParam2, strUsage)
LineOut "/" & strOption & " " & strParam1 & " " & strParam2
LineOut " " & strUsage
End Sub
Private Sub OptLine3(strOption, strParam1, strParam2, strParam3, strUsage)
LineOut "/" & strOption & " " & strParam1 & " " & strParam2 & " " & strParam3
LineOut " " & strUsage
End Sub
Private Sub ExecCommandLine
Dim intOption, indexOption
Dim strOption, chOpt
Dim remoteInfo(3)
' First three parameters before "/" or "-" may be remote connection info
remoteInfo(0) = "."
intOption = intUnknownOption
For indexOption = 0 To 3
If indexOption >= WScript.Arguments.Count Then
Exit For
End If
strOption = WScript.Arguments.Item(indexOption)
chOpt = Left(strOption, 1)
If chOpt = "/" Or chOpt = "-" Then
intOption = intKnownOption
Exit For
End If
remoteInfo(indexOption) = strOption
Next
' Connect to remote only if syntax is reasonably good
If intUnknownOption = intOption Or 2 = indexOption Then
g_strComputer = "."
intOption = intUnknownOption
Else
g_strComputer = remoteInfo(0)
g_strUserName = remoteInfo(1)
g_strPassword = remoteInfo(2)
End If
Call Connect()
If intUnknownOption = intOption Then
End If
intOption = ParseCommandLine(indexOption)
If intUnknownOption = intOption Then
End If
End Sub
Private Function ParseCommandLine(index)
Dim strOption, chOpt
ParseCommandLine = intKnownOption
chOpt = Left(strOption, 1)
If (chOpt <> "-") And (chOpt <> "/") Then
ParseCommandLine = intUnknownOption
Exit Function
End If
strOption = Right(strOption, Len(strOption) - 1)
If strOption = findar("L_optInstallLicense") Then
If HandleOptionParam(index+1, True, findar("L_optInstallLicense"), findar("L_ParamsLicenseFile")) Then
InstallLicense WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optInstallProductKey") Then
If HandleOptionParam(index+1, True, findar("L_optInstallProductKey"), findar("L_ParamsProductKey")) Then
InstallProductKey WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optUninstallProductKey") Then
If HandleOptionParam(index+1, False, findar("L_optUninstallProductKey"), findar("L_ParamsActivationIDOptional")) Then
UninstallProductKey WScript.Arguments.Item(index+1)
Else
UninstallProductKey ""
End If
ElseIf strOption = findar("L_optDisplayIID") Then
If HandleOptionParam(index+1, False, findar("L_optDisplayIID"), findar("L_ParamsActivationIDOptional")) Then
DisplayIID WScript.Arguments.Item(index+1)
Else
DisplayIID ""
End If
ElseIf strOption = findar("L_optActivateProduct") Then
If HandleOptionParam(index+1, False, findar("L_optActivateProduct"), findar("L_ParamsActivationIDOptional")) Then
ActivateProduct WScript.Arguments.Item(index+1)
Else
ActivateProduct ""
End If
ElseIf strOption = findar("L_optPhoneActivateProduct") Then
If HandleOptionParam(index+1, True, findar("L_optPhoneActivateProduct"), findar("L_ParamsPhoneActivate")) Then
If HandleOptionParam(index+2, False, findar("L_optPhoneActivateProduct"), findar("L_ParamsActivationIDOptional")) Then
PhoneActivateProduct WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
Else
PhoneActivateProduct WScript.Arguments.Item(index+1), ""
End If
End If
ElseIf strOption = findar("L_optDisplayInformation") Then
If HandleOptionParam(index+1, False, findar("L_optDisplayInformation"), "") Then
DisplayAllInformation WScript.Arguments.Item(index+1), False
Else
DisplayAllInformation "", False
End If
ElseIf strOption = findar("L_optDisplayInformationVerbose") Then
If HandleOptionParam(index+1, False, findar("L_optDisplayInformationVerbose"), "") Then
DisplayAllInformation WScript.Arguments.Item(index+1), True
Else
DisplayAllInformation "", True
End If
ElseIf strOption = findar("L_optClearPKeyFromRegistry") Then
ClearPKeyFromRegistry
ElseIf strOption = findar("L_optReinstallLicenses") Then
ReinstallLicenses
ElseIf strOption = findar("L_optReArmWindows") Then
ReArmWindows()
ElseIf strOption = findar("L_optReArmApplication") Then
If HandleOptionParam(index+1, True, findar("L_optReArmApplication"), findar("L_ParamsApplicationID")) Then
ReArmApp WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optReArmSku") Then
If HandleOptionParam(index+1, True, findar("L_optReArmSku"), findar("L_ParamsActivationID")) Then
ReArmSku WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optExpirationDatime") Then
If HandleOptionParam(index+1, False, findar("L_optExpirationDatime"), findar("L_ParamsActivationIDOptional")) Then
ExpirationDatime WScript.Arguments.Item(index+1)
Else
ExpirationDatime ""
End If
ElseIf strOption = findar("L_optSetKmsName") Then
If HandleOptionParam(index+1, True, findar("L_optSetKmsName"), findar("L_ParamsSetKms")) Then
If HandleOptionParam(index+2, False, findar("L_optSetKmsName"), findar("L_ParamsActivationIDOptional")) Then
SetKmsMachineName WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
Else
SetKmsMachineName WScript.Arguments.Item(index+1), ""
End If
End If
ElseIf strOption = findar("L_optClearKmsName") Then
If HandleOptionParam(index+1, False, findar("L_optClearKmsName"), findar("L_ParamsActivationIDOptional")) Then
ClearKms WScript.Arguments.Item(index+1)
Else
ClearKms ""
End If
ElseIf strOption = findar("L_optSetKmsLookupDomain") Then
If HandleOptionParam(index+1, True, findar("L_optSetKmsLookupDomain"), findar("L_ParamsSetKmsLookupDomain")) Then
If HandleOptionParam(index+2, False, findar("L_optSetKmsLookupDomain"), findar("L_ParamsActivationIDOptional")) Then
SetKmsLookupDomain WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
Else
SetKmsLookupDomain WScript.Arguments.Item(index+1), ""
End If
End If
ElseIf strOption = findar("L_optClearKmsLookupDomain") Then
If HandleOptionParam(index+1, False, findar("L_optClearKmsLookupDomain"), findar("L_ParamsActivationIDOptional")) Then
ClearKmsLookupDomain WScript.Arguments.Item(index+1)
Else
ClearKmsLookupDomain ""
End If
ElseIf strOption = findar("L_optSetKmsHostCaching") Then
SetHostCachingDisable(False)
ElseIf strOption = findar("L_optClearKmsHostCaching") Then
SetHostCachingDisable(True)
ElseIf strOption = findar("L_optSetActivationInterval") Then
If HandleOptionParam(index+1, True, findar("L_optSetActivationInterval"), findar("L_ParamsSetActivationInterval")) Then
SetActivationInterval WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optSetRenewalInterval") Then
If HandleOptionParam(index+1, True, findar("L_optSetRenewalInterval"), findar("L_ParamsSetRenewalInterval")) Then
SetRenewalInterval WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optSetKmsListenPort") Then
If HandleOptionParam(index+1, True, findar("L_optSetKmsListenPort"), findar("L_ParamsSetListenKmsPort")) Then
SetKmsListenPort WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optSetDNS") Then
SetDnsPublishingDisabled(False)
ElseIf strOption = findar("L_optClearDNS") Then
SetDnsPublishingDisabled(True)
ElseIf strOption = findar("L_optSetNormalPriority") Then
SetKmsLowPriority(False)
ElseIf strOption = findar("L_optClearNormalPriority") Then
SetKmsLowPriority(True)
ElseIf strOption = findar("L_optSetVLActivationType") Then
If HandleOptionParam(index+1, False, findar("L_optSetVLActivationType"), findar("L_ParamsVLActivationTypeOptional")) Then
If HandleOptionParam(index+2, False, findar("L_optSetVLActivationType"), findar("L_ParamsActivationIDOptional")) Then
SetVLActivationType WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
Else
SetVLActivationType WScript.Arguments.Item(index+1), ""
End If
Else
SetVLActivationType Null, ""
End If
ElseIf strOption = findar("L_optListInstalledILs") Then
TkaListILs
ElseIf strOption = findar("L_optRemoveInstalledIL") Then
If HandleOptionParam(index+2, True, findar("L_optRemoveInstalledIL"), findar("L_ParamsRemoveInstalledIL")) Then
TkaRemoveIL WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
End If
ElseIf strOption = findar("L_optListTkaCerts") Then
TkaListCerts
ElseIf strOption = findar("L_optForceTkaActivation") Then
If HandleOptionParam(index+2, False, findar("L_optForceTkaActivation"), findar("L_ParamsForceTkaActivation")) Then
TkaActivate WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
ElseIf HandleOptionParam(index+1, True, findar("L_optForceTkaActivation"), findar("L_ParamsForceTkaActivation")) Then
TkaActivate WScript.Arguments.Item(index+1), ""
End If
ElseIf strOption = findar("L_optADGetIID") Then
If HandleOptionParam(index+1, True, findar("L_optADGetIID"), findar("L_ParamsProductKey")) Then
ADGetIID WScript.Arguments.Item(index+1)
End If
ElseIf strOption = findar("L_optADActivate") Then
If HandleOptionParam(index+1, True, findar("L_optADActivate"), findar("L_ParamsProductKey")) Then
If HandleOptionParam(index+2, False, findar("L_optADActivate"), findar("L_ParamsAONameOptional")) Then
ADActivateOnline WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2)
Else
ADActivateOnline WScript.Arguments.Item(index+1), ""
End If
End If
ElseIf strOption = findar("L_optADApplyCID") Then
If HandleOptionParam(index+1, True, findar("L_optADApplyCID"), findar("L_ParamsProductKey")) Then
If HandleOptionParam(index+2, True, findar("L_optADApplyCID"), findar("L_ParamsPhoneActivate")) Then
If HandleOptionParam(index+3, False, findar("L_optADApplyCID"), findar("L_ParamsAONameOptional")) Then
ADActivatePhone WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2), WScript.Arguments.Item(index+3)
Else
ADActivatePhone WScript.Arguments.Item(index+1), WScript.Arguments.Item(index+2), ""
End If
End If
End If
ElseIf strOption = findar("L_optADListAOs") Then
ADListActivationObjects
ElseIf strOption = findar("L_optADDeleteAO") Then
If HandleOptionParam(index+1, True, findar("L_optADDeleteAO"), findar("L_ParamsAODistinguishedName")) Then
ADDeleteActivationObjects WScript.Arguments.Item(index+1)
End If
Else
ParseCommandLine = intUnknownOption
End If
End Function
' global options
Private Function CheckProductForCommand(objProduct, strActivationID)
Dim bCheckProductForCommand
bCheckProductForCommand = False
If (strActivationID = "" And LCase(objProduct.ApplicationId) = WindowsAppId And (objProduct.LicenseIsAddon = False)) Then
bCheckProductForCommand = True
End If
If (LCase(objProduct.ID) = strActivationID) Then
bCheckProductForCommand = True
End If
CheckProductForCommand = bCheckProductForCommand
End Function
Private Sub UninstallProductKey(strActivationID)
Dim objService, objProduct
Dim lRet, strVersion, strDescription
Dim kmsServerFound, uninstallDone
Dim iIsPrimaryWindowsSku, bPrimaryWindowsSkuKeyUninstalled
Dim bCheckProductForCommand
On Error Resume Next
strActivationID = LCase(strActivationID)
kmsServerFound = False
uninstallDone = False
set objService = GetServiceObject("Version")
strVersion = objService.Version
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause & ", ProductKeyID", PartialProductKeyNonNullWhereClause)
strDescription = objProduct.Description
bCheckProductForCommand = CheckProductForCommand(objProduct, strActivationID)
If (bCheckProductForCommand) Then
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (strActivationID = "") And (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
objProduct.UninstallProductKey()
QuitIfError()
' Uninstalling a product key could change Windows licensing state.
' Since the service determines if it can shut down and when is the next start time
' based on the licensing state we should reconsume the licenses here.
objService.RefreshLicenseStatus()
' For Windows (i.e. if no activationID specified), always
' ensure that product-key for primary SKU is uninstalled
If (strActivationID <> "") Or (iIsPrimaryWindowsSku = 1) Then
uninstallDone = True
End If
LineOut findar("L_MsgUninstalledPKey")
' Check whether a ActID belongs to KMS server.
' Do this for all ActID other than one whose pkey is being uninstalled
ElseIf IsKmsServer(strDescription) Then
kmsServerFound = True
End If
If (kmsServerFound = True) And (uninstallDone = True) Then
Exit For
End If
Next
If kmsServerFound = True Then
' Set the KMS version in the registry (both 64 and 32 bit locations)
lRet = SetRegistryStr(HKEY_LOCAL_MACHINE, SLKeyPath, "KeyManagementServiceVersion", strVersion)
If (lRet <> 0) Then
QuitWithError lRet
End If
lRet = SetRegistryStr(HKEY_LOCAL_MACHINE, SLKeyPath32, "KeyManagementServiceVersion", strVersion)
If (lRet <> 0) Then
QuitWithError lRet
End If
Else
' Clear the KMS version from the registry (both 64 and 32 bit locations)
lRet = DeleteRegistryValue(HKEY_LOCAL_MACHINE, SLKeyPath, "KeyManagementServiceVersion")
If (lRet <> 0 And lRet <> 2) Then
QuitWithError lRet
End If
lRet = DeleteRegistryValue(HKEY_LOCAL_MACHINE, SLKeyPath32, "KeyManagementServiceVersion")
If (lRet <> 0 And lRet <> 2) Then
QuitWithError lRet
End If
End If
If uninstallDone = False Then
LineOut findar("L_MsgErrorPKey")
End If
End Sub
Private Sub DisplayIID(strActivationID)
Dim objProduct
Dim iIsPrimaryWindowsSku, bFoundAtLeastOneKey
Dim bCheckProductForCommand
strActivationID = LCase(strActivationID)
bFoundAtLeastOneKey = False
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause & ", OfflineInstallationId", PartialProductKeyNonNullWhereClause)
bCheckProductForCommand = CheckProductForCommand(objProduct, strActivationID)
If (bCheckProductForCommand) Then
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (strActivationID = "") And (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
LineOut findar("L_MsgInstallationID") & objProduct.OfflineInstallationId
bFoundAtLeastOneKey = True
If (strActivationID <> "") Or (iIsPrimaryWindowsSku = 1) Then
Exit Sub
End If
End If
Next
If (bFoundAtLeastOneKey = TRUE) Then
LineOut ""
LineOut findar("L_MsgPhoneNumbers")
Else
LineOut findar("L_MsgErrorProductNotFound")
End If
End Sub
Private Sub DisplayActivatingSku(objProduct)
Dim strOutput
strOutput = Replace(findar("L_MsgActivating"), "%PRODUCTNAME%", objProduct.Name)
strOutput = Replace(strOutput, "%PRODUCTID%", objProduct.ID)
LineFlush strOutput
End Sub
Private Sub DisplayActivatedStatus(objProduct)
If (objProduct.LicenseStatus = 1) Then
LineOut findar("L_MsgActivated")
ElseIf (objProduct.LicenseStatus = 4) Then
LineOut findar("L_MsgErrorText_8") & findar("L_MsgErrorText_11")
ElseIf ((objProduct.LicenseStatus = 5) And (objProduct.LicenseStatusReason = HR_SL_E_NOT_GENUINE)) Then
LineOut findar("L_MsgErrorText_8") & findar("L_MsgErrorText_12")
ElseIf (objProduct.LicenseStatus = 6) Then
LineOut findar("L_MsgActivated")
LineOut findar("L_MsgLicenseStatusExtendedGrace_1")
Else
LineOut findar("L_MsgActivated_Failed")
End If
End Sub
Private Sub ActivateProduct(strActivationID)
Dim objService, objProduct
Dim iIsPrimaryWindowsSku, bFoundAtLeastOneKey
Dim strOutput
Dim bCheckProductForCommand
strActivationID = LCase(strActivationID)
bFoundAtLeastOneKey = False
set objService = GetServiceObject("Version")
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause & ", LicenseStatus, VLActivationTypeEnabled", PartialProductKeyNonNullWhereClause)
bCheckProductForCommand = CheckProductForCommand(objProduct, strActivationID)
If (bCheckProductForCommand) Then
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (strActivationID = "") And (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
'
' This routine does not perform token-based activation.
' If configured for TA, then show message to user.
'
If (objProduct.VLActivationTypeEnabled = 3) Then
LineOut findar("L_MsgTokenBasedActivationMustBeDone")
Exit Sub
End If
strOutput = Replace(findar("L_MsgActivating"), "%PRODUCTNAME%", objProduct.Name)
strOutput = Replace(strOutput, "%PRODUCTID%", objProduct.ID)
LineOut strOutput
On Error Resume Next
'
' Avoid using a MAK activation count up unless needed
'
If (Not(IsMAK(objProduct.Description)) Or (objProduct.LicenseStatus <> 1)) Then
objProduct.Activate()
QuitIfError()
objService.RefreshLicenseStatus()
objProduct.refresh_
End If
DisplayActivatedStatus objProduct
bFoundAtLeastOneKey = True
If (strActivationID <> "") Or (iIsPrimaryWindowsSku = 1) Then
Exit Sub
End If
End If
Next
If (bFoundAtLeastOneKey = True) Then
Exit Sub
End If
LineOut findar("L_MsgErrorProductNotFound")
End Sub
Private Sub PhoneActivateProduct(strCID, strActivationID)
Dim objService, objProduct
Dim iIsPrimaryWindowsSku, bFoundAtLeastOneKey
Dim strOutput
Dim bCheckProductForCommand
strActivationID = LCase(strActivationID)
bFoundAtLeastOneKey = False
set objService = GetServiceObject("Version")
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause & ", OfflineInstallationId, LicenseStatus, LicenseStatusReason", PartialProductKeyNonNullWhereClause)
bCheckProductForCommand = CheckProductForCommand(objProduct, strActivationID)
If (bCheckProductForCommand) Then
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (strActivationID = "") And (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
On Error Resume Next
objProduct.DepositOfflineConfirmationId objProduct.OfflineInstallationId, strCID
QuitIfError()
objService.RefreshLicenseStatus()
objProduct.refresh_
If (objProduct.LicenseStatus = 1) Then
strOutput = Replace(findar("L_MsgConfID"), "%ACTID%", objProduct.ID)
LineOut strOutput
ElseIf (objProduct.LicenseStatus = 4) Then
LineOut findar("L_MsgErrorText_8") & findar("L_MsgErrorText_11")
ElseIf ((objProduct.LicenseStatus = 5) And (objProduct.LicenseStatusReason = HR_SL_E_NOT_GENUINE)) Then
LineOut findar("L_MsgErrorText_8") & findar("L_MsgErrorText_12")
ElseIf (objProduct.LicenseStatus = 6) Then
LineOut findar("L_MsgActivated")
LineOut findar("L_MsgLicenseStatusExtendedGrace_1")
Else
LineOut findar("L_MsgActivated_Failed")
End If
bFoundAtLeastOneKey = True
If (strActivationID <> "") Or (iIsPrimaryWindowsSku = 1) Then
Exit Sub
End If
End If
Next
If (bFoundAtLeastOneKey = True) Then
Exit Sub
End If
LineOut findar("L_MsgErrorProductNotFound")
End Sub
Private Sub DisplayKMSInformation(objService, objProduct)
Dim dwValue
Dim boolValue
Dim KeyManagementServiceTotalRequests
Dim objProductKMSValues
set objProductKMSValues = GetProductObject( _
"IsKeyManagementServiceMachine, KeyManagementServiceCurrentCount, " & _
"KeyManagementServiceTotalRequests, KeyManagementServiceFailedRequests, " & _
"KeyManagementServiceUnlicensedRequests, KeyManagementServiceLicensedRequests, " & _
"KeyManagementServiceOOBGraceRequests, KeyManagementServiceOOTGraceRequests, " & _
"KeyManagementServiceNonGenuineGraceRequests, KeyManagementServiceNotificationRequests", _
"id = '" & objProduct.ID & "'")
If objProductKMSValues.IsKeyManagementServiceMachine > 0 Then
LineOut ""
LineOut findar("L_MsgKmsEnabled")
LineOut " " & findar("L_MsgKmsCurrentCount") & objProductKMSValues.KeyManagementServiceCurrentCount
dwValue = objService.KeyManagementServiceListeningPort
If 0 = dwValue Then
LineOut " " & findar("L_MsgKmsListeningOnPort") & DefaultPort
Else
LineOut " " & findar("L_MsgKmsListeningOnPort") & dwValue
End If
boolValue = objService.KeyManagementServiceDnsPublishing
If true = boolValue Then
LineOut " " & findar("L_MsgKmsDnsPublishingEnabled")
Else
LineOut " " & findar("L_MsgKmsDnsPublishingDisabled")
End If
boolValue = objService.KeyManagementServiceLowPriority
If false = boolValue Then
LineOut " " & findar("L_MsgKmsPriNormal")
Else
LineOut " " & findar("L_MsgKmsPriLow")
End If
On Error Resume Next
KeyManagementServiceTotalRequests = objProductKMSValues.KeyManagementServiceTotalRequests
If (Not(IsNull(KeyManagementServiceTotalRequests))) And (Not(IsEmpty(KeyManagementServiceTotalRequests))) Then
LineOut ""
LineOut findar("L_MsgKmsCumulativeRequestsFromClients")
LineOut " " & findar("L_MsgKmsTotalRequestsRecieved") & objProductKMSValues.KeyManagementServiceTotalRequests
LineOut " " & findar("L_MsgKmsFailedRequestsReceived") & objProductKMSValues.KeyManagementServiceFailedRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusUnlicensed") & objProductKMSValues.KeyManagementServiceUnlicensedRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusLicensed") & objProductKMSValues.KeyManagementServiceLicensedRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusInitialGrace") & objProductKMSValues.KeyManagementServiceOOBGraceRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusLicenseExpiredOrHwidOot") & objProductKMSValues.KeyManagementServiceOOTGraceRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusNonGenuineGrace") & objProductKMSValues.KeyManagementServiceNonGenuineGraceRequests
LineOut " " & findar("L_MsgKmsRequestsWithStatusNotification") & objProductKMSValues.KeyManagementServiceNotificationRequests
End If
End If
End Sub
Private Sub DisplayADClientInformation(objService, objProduct)
LineOut ""
LineOut findar("L_MsgVLMostRecentActivationInfo")
LineOut findar("L_MsgADInfo")
LineOut " " & findar("L_MsgADInfoAOName") & objProduct.ADActivationObjectName
LineOut " " & findar("L_MsgADInfoAODN") & objProduct.ADActivationObjectDN
LineOut " " & findar("L_MsgADInfoExtendedPid") & objProduct.ADActivationCsvlkPid
LineOut " " & findar("L_MsgADInfoActID") & objProduct.ADActivationCsvlkSkuId
End Sub
Private Sub DisplayTkaClientInformation(objService, objProduct)
LineOut ""
LineOut findar("L_MsgVLMostRecentActivationInfo")
LineOut findar("L_MsgTkaInfo")
LineOut " " & Replace(findar("L_MsgTkaInfoILID" ), "%ILID%" , objProduct.TokenActivationILID)
LineOut " " & Replace(findar("L_MsgTkaInfoILVID" ), "%ILVID%" , objProduct.TokenActivationILVID)
LineOut " " & Replace(findar("L_MsgTkaInfoGrantNo" ), "%GRANTNO%" , objProduct.TokenActivationGrantNumber)
LineOut " " & Replace(findar("L_MsgTkaInfoThumbprint"), "%THUMBPRINT%", objProduct.TokenActivationCertificateThumbprint)
End Sub
Private Sub DisplayKMSClientInformation(objService, objProduct)
Dim strKms, strIpAddress, strPort, strOutput
Dim iVLRenewalInterval, iVLActivationInterval
Dim bFixedKms, bKmsLookupDomain, strKmsLookupDomain
iVLRenewalInterval = objProduct.VLRenewalInterval
iVLActivationInterval = objProduct.VLActivationInterval
LineOut ""
LineOut findar("L_MsgVLMostRecentActivationInfo")
LineOut findar("L_MsgKmsInfo")
LineOut " " & findar("L_MsgCmid") & objService.ClientMachineID
strKmsLookupDomain = objProduct.KeyManagementServiceLookupDomain
If strKmsLookupDomain <> "" and Not IsNull(strKmsLookupDomain) Then
bKmsLookupDomain = True
LineOut " " & findar("L_MsgKmsLookupDomain") & strKmsLookupDomain
End If
strKms = objProduct.KeyManagementServiceMachine
if strKms <> "" And Not IsNull(strKms) Then
bFixedKms = True
strPort = objProduct.KeyManagementServicePort
If (strPort = 0) Then
strPort = DefaultPort
End If
LineOut " " & findar("L_MsgRegisteredKmsName") & strKms & ":" & strPort
Else
strKms = objProduct.DiscoveredKeyManagementServiceMachineName
strPort = objProduct.DiscoveredKeyManagementServiceMachinePort
If IsNull(strKms) Or (strKms = "") Or IsNull(strPort) Or (strPort = 0) Then
LineOut " " & findar("L_MsgKmsFromDnsUnavailable")
Else
LineOut " " & findar("L_MsgKmsFromDns") & strKms & ":" & strPort
End If
End If
strIpAddress = objProduct.DiscoveredKeyManagementServiceMachineIpAddress
If IsNull(strIpAddress) Or (strIpAddress = "") Then
LineOut " " & findar("L_MsgKmsIpAddressUnavailable")
Else
LineOut " " & findar("L_MsgKmsIpAddress") & strIpAddress
End If
LineOut " " & findar("L_MsgKmsPID4") & objProduct.KeyManagementServiceProductKeyID
strOutput = Replace(findar("L_MsgActivationInterval"), "%INTERVAL%", iVLActivationInterval)
LineOut " " & strOutput
strOutput = Replace(findar("L_MsgRenewalInterval"), "%INTERVAL%", iVLRenewalInterval)
LineOut " " & strOutput
if (objService.KeyManagementServiceHostCaching = True) Then
LineOut " " & findar("L_MsgKmsHostCachingEnabled")
Else
LineOut " " & findar("L_MsgKmsHostCachingDisabled")
End If
If bKmsLookupDomain And bFixedKms Then
LineOut ""
LineOut Replace(findar("L_MsgKmsUseMachineNameOverrides"), "%KMS%", strKms & ":" & strPort)
End If
End Sub
Private Sub DisplayAVMAClientInformation(objProduct)
Dim strHostName, strPid
Dim displayDate
Dim bHostName, bFiletime, bPid
strHostName = objProduct.AutomaticVMActivationHostMachineName
bHostName = strHostName <> "" And Not IsNull(strHostName)
Set displayDate = CreateObject("WBemScripting.SWbemDateTime")
displayDate.Value = objProduct.AutomaticVMActivationLastActivationTime
bFiletime = displayDate.GetFileTime(false) <> 0
strPid = objProduct.AutomaticVMActivationHostDigitalPid2
bPid = strPid <> "" And Not IsNull(strPid)
If bHostName Or bFiletime Or bPid Then
LineOut ""
LineOut findar("L_MsgVLMostRecentActivationInfo")
LineOut findar("L_MsgAVMAInfo")
If bHostName Then
LineOut " " & findar("L_MsgAVMAHostMachineName") & strHostName
Else
LineOut " " & findar("L_MsgAVMAHostMachineName") & findar("L_MsgNotAvailable")
End If
If bFiletime Then
LineOut " " & findar("L_MsgAVMALastActTime") & displayDate.GetVarDate
Else
LineOut " " & findar("L_MsgAVMALastActTime") & findar("L_MsgNotAvailable")
End If
If bPid Then
LineOut " " & findar("L_MsgAVMAHostPid2") & strPid
Else
LineOut " " & findar("L_MsgAVMAHostPid2") & findar("L_MsgNotAvailable")
End If
End If
End Sub
' Display all information for /dlv and /dli
' If you add need to access new properties through WMI you must add them to the
' queries for service/object. Be sure to check that the object properties in DisplayAllInformation()
' are requested for function/methods such as GetIsPrimaryWindowsSKU() and DisplayKMSClientInformation().
Private Sub DisplayAllInformation(strParm, bVerbose)
Dim objService, objProduct
Dim strServiceSelectClause
Dim objProductIter, strIterSelectClause, strProductSelectClause
Dim strDescription, bKmsClient, strSLActID, bKmsServer, bTBL
Dim strAVMAId, bAVMA
Dim ls, gpMin, gpDay, displayDate
Dim strOutput
Dim strUrl
Dim bShowSkuInformation
Dim iIsPrimaryWindowsSku, bUseDefault
Dim productKeyFound
Dim strErr
strParm = LCase(strParm)
productKeyFound = False
strServiceSelectClause = _
"KeyManagementServiceListeningPort, KeyManagementServiceDnsPublishing, " & _
"KeyManagementServiceLowPriority, ClientMachineId, KeyManagementServiceHostCaching, " & _
"Version"
strProductSelectClause = _
ProductIsPrimarySkuSelectClause & ", " & _
"ProductKeyID, ProductKeyChannel, OfflineInstallationId, " & _
"ProcessorURL, MachineURL, UseLicenseURL, ProductKeyURL, ValidationURL, " & _
"GracePeriodRemaining, LicenseStatus, LicenseStatusReason, EvaluationEndDate, " & _
"VLRenewalInterval, VLActivationInterval, KeyManagementServiceLookupDomain, KeyManagementServiceMachine, " & _
"KeyManagementServicePort, DiscoveredKeyManagementServiceMachineName, " & _
"DiscoveredKeyManagementServiceMachinePort, DiscoveredKeyManagementServiceMachineIpAddress, KeyManagementServiceProductKeyID," & _
"TokenActivationILID, TokenActivationILVID, TokenActivationGrantNumber," & _
"TokenActivationCertificateThumbprint, TokenActivationAdditionalInfo, TrustedTime," & _
"ADActivationObjectName, ADActivationObjectDN, ADActivationCsvlkPid, ADActivationCsvlkSkuId, VLActivationTypeEnabled, VLActivationType," & _
"IAID, AutomaticVMActivationHostMachineName, AutomaticVMActivationLastActivationTime, AutomaticVMActivationHostDigitalPid2"
If bVerbose Then
strServiceSelectClause = "RemainingWindowsReArmCount, " & strServiceSelectClause
strProductSelectClause = "RemainingAppReArmCount, RemainingSkuReArmCount, " & strProductSelectClause
End If
set objService = GetServiceObject(strServiceSelectClause)
If bVerbose Then
LineOut findar("L_MsgServiceVersion") & objService.Version
End If
If (strParm = "all") Then
strIterSelectClause = strProductSelectClause
Else
strIterSelectClause = ProductIsPrimarySkuSelectClause
End If
For Each objProductIter in GetProductCollection(strIterSelectClause, EmptyWhereClause)
strSLActID = objProductIter.ID
' Display information if:
' parm = "all" or
' ActID = parm or
' default to current ActID (parm = "" and IsPrimaryWindowsSKU is 1 or 2)
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProductIter)
bUseDefault = False
bShowSkuInformation = False
If (strParm = "" And ((iIsPrimaryWindowsSku = 1) Or (iIsPrimaryWindowsSku = 2))) Then
bUseDefault = True
bShowSkuInformation = True
End If
If (strParm = "" And (objProductIter.LicenseIsAddon And objProductIter.PartialProductKey <> "")) Then
bShowSkuInformation = True
End If
If (strParm = "all") Then
bShowSkuInformation = True
End If
If (strParm = LCase(strSLActID)) Then
bShowSkuInformation = True
End If
If (bShowSkuInformation) Then
If (strParm = "all") Then
set objProduct = objProductIter
Else
set objProduct = GetProductObject(strProductSelectClause, "id = '" & objProductIter.ID & "'")
End If
strDescription = objProduct.Description
'If the user didn't specify anything and we are showing the default case, warn them
' if this can't be verified as the primary SKU
If ((bUseDefault = True) And (iIsPrimaryWindowsSku = 2)) Then
OutputIndeterminateOperationWarning(objProduct)
End IF
productKeyFound = True
LineOut ""
LineOut findar("L_MsgProductName") & objProduct.Name
LineOut findar("L_MsgProductDesc") & strDescription
If objProduct.TokenActivationAdditionalInfo <> "" Then
LineOut Replace( _
findar("L_MsgTkaInfoAdditionalInfo"), _
"%MOREINFO%", _
objProduct.TokenActivationAdditionalInfo _
)
End If
bKmsServer = IsKmsServer(strDescription)
bKmsClient = IsKmsClient(strDescription)
bTBL = IsTBL(strDescription)
bAVMA = IsAVMA(strDescription)
If bVerbose Then
LineOut findar("L_MsgActID") & strSLActID
LineOut findar("L_MsgAppID") & objProduct.ApplicationID
LineOut findar("L_MsgPID4") & objProduct.ProductKeyID
LineOut findar("L_MsgChannel") & objProduct.ProductKeyChannel
LineOut findar("L_MsgInstallationID") & objProduct.OfflineInstallationId
If (NOT bKmsClient) AND (NOT bAVMA) Then
'Note that we are re-using the UseLicenseURL for the Product Activation
'URL for down-level compatibility reasons
strUrl = objProduct.ProcessorURL
If strUrl <> "" Then
LineOut findar("L_MsgProcessorCertUrl") & strUrl
End If
strUrl = objProduct.MachineURL
If strUrl <> "" Then
LineOut findar("L_MsgMachineCertUrl") & strUrl
End If
strUrl = objProduct.UseLicenseURL
If strUrl <> "" Then
LineOut findar("L_MsgUseLicenseCertUrl") & strUrl
End If
strUrl = objProduct.ProductKeyURL
If strUrl <> "" Then
LineOut findar("L_MsgPKeyCertUrl") & strUrl
End If
strUrl = objProduct.ValidationURL
If strUrl <> "" Then
LineOut findar("L_MsgValidationUrl") & strUrl
End If
End If
End If
If objProduct.PartialProductKey <> "" Then
LineOut findar("L_MsgPartialPKey") & objProduct.PartialProductKey
Else
LineOut findar("L_MsgErrorLicenseNotInUse")
End If
ls = objProduct.LicenseStatus
If ls = 0 Then
LineOut findar("L_MsgLicenseStatusUnlicensed_1")
ElseIf ls = 1 Then
LineOut findar("L_MsgLicenseStatusLicensed_1")
gpMin = objProduct.GracePeriodRemaining
If (gpMin <> 0) Then
gpDay = GetDaysFromMins(gpMin)
If (bTBL) Then
strOutput = Replace(findar("L_MsgLicenseStatusTBL_1"), "%MINUTE%", gpMin)
ElseIf (bAVMA) Then
strOutput = Replace(findar("L_MsgLicenseStatusAVMA_1"), "%MINUTE%", gpMin)
Else
strOutput = Replace(findar("L_MsgLicenseStatusVL_1"), "%MINUTE%", gpMin)
End If
strOutput = Replace(strOutput, "%DAY%", gpDay)
LineOut strOutput
End If
ElseIf ls = 2 Then
LineOut findar("L_MsgLicenseStatusInitialGrace_1")
gpMin = objProduct.GracePeriodRemaining
gpDay = GetDaysFromMins(gpMin)
strOutput = Replace(findar("L_MsgLicenseStatusTimeRemaining"), "%MINUTE%", gpMin)
strOutput = Replace(strOutput, "%DAY%", gpDay)
LineOut strOutput
ElseIf ls = 3 Then
LineOut findar("L_MsgLicenseStatusAdditionalGrace_1")
gpMin = objProduct.GracePeriodRemaining
gpDay = GetDaysFromMins(gpMin)
strOutput = Replace(findar("L_MsgLicenseStatusTimeRemaining"), "%MINUTE%", gpMin)
strOutput = Replace(strOutput, "%DAY%", gpDay)
LineOut strOutput
ElseIf ls = 4 Then
LineOut findar("L_MsgLicenseStatusNonGenuineGrace_1")
gpMin = objProduct.GracePeriodRemaining
gpDay = GetDaysFromMins(gpMin)
strOutput = Replace(findar("L_MsgLicenseStatusTimeRemaining"), "%MINUTE%", gpMin)
strOutput = Replace(strOutput, "%DAY%", gpDay)
LineOut strOutput
ElseIf ls = 5 Then
LineOut findar("L_MsgLicenseStatusNotification_1")
strErr = CStr(Hex(objProduct.LicenseStatusReason))
if (objProduct.LicenseStatusReason = HR_SL_E_NOT_GENUINE) Then
strOutput = Replace(findar("L_MsgNotificationErrorReasonNonGenuine"), "%ERRCODE%", strErr)
ElseIf (objProduct.LicenseStatusReason = HR_SL_E_GRACE_TIME_EXPIRED) Then
strOutput = Replace(findar("L_MsgNotificationErrorReasonExpiration"), "%ERRCODE%", strErr)
Else
strOutput = Replace(findar("L_MsgNotificationErrorReasonOther"), "%ERRCODE%", strErr)
End If
LineOut strOutput
ElseIf ls = 6 Then
LineOut findar("L_MsgLicenseStatusExtendedGrace_1")
gpMin = objProduct.GracePeriodRemaining
gpDay = GetDaysFromMins(gpMin)
strOutput = Replace(findar("L_MsgLicenseStatusTimeRemaining"), "%MINUTE%", gpMin)
strOutput = Replace(strOutput, "%DAY%", gpDay)
LineOut strOutput
Else
LineOut findar("L_MsgLicenseStatusUnknown")
End If
If (ls <> 0 And bVerbose) Then
Set displayDate = CreateObject("WBemScripting.SWbemDateTime")
displayDate.Value = objProduct.EvaluationEndDate
If (displayDate.GetFileTime(false) <> 0) Then
LineOut findar("L_MsgLicenseStatusEvalEndData") & displayDate.GetVarDate
End If
End If
If (bVerbose) Then
If (LCase(objProduct.ApplicationId) = WindowsAppId) Then
LineOut Replace(findar("L_MsgRemainingWindowsRearmCount"), "%COUNT%", objService.RemainingWindowsReArmCount)
Else
LineOut Replace(findar("L_MsgRemainingAppRearmCount"), "%COUNT%", objProduct.RemainingAppReArmCount)
End If
LineOut Replace(findar("L_MsgRemainingSkuRearmCount"), "%COUNT%", objProduct.RemainingSkuReArmCount)
Set displayDate = CreateObject("WBemScripting.SWbemDateTime")
displayDate.Value = objProduct.TrustedTime
If (displayDate.GetFileTime(false) <> 0) Then
LineOut findar("L_MsgCurrentTrustedTime") & displayDate.GetVarDate
End If
End If
'
' KMS client properties
'
If bKmsClient Then
If (objProduct.VLActivationTypeEnabled = 1) Then
LineOut findar("L_MsgVLActivationTypeAD")
ElseIf (objProduct.VLActivationTypeEnabled = 2) Then
LineOut findar("L_MsgVLActivationTypeKMS")
ElseIf (objProduct.VLActivationTypeEnabled = 3) Then
LineOut findar("L_MsgVLActivationTypeToken")
Else
LineOut findar("L_MsgVLActivationTypeAll")
End If
If IsADActivated(objProduct) Then
DisplayADClientInformation objService, objProduct
ElseIf IsTokenActivated(objProduct) Then
DisplayTkaClientInformation objService, objProduct
ElseIf ls <> 1 Then
LineOut findar("L_MsgPleaseActivateRefreshKMSInfo")
Else
DisplayKMSClientInformation objService, objProduct
End If
End If
If (bKmsServer Or (iIsPrimaryWindowsSku = 1) Or (iIsPrimaryWindowsSku = 2)) Then
DisplayKMSInformation objService, objProduct
End If
If (bAVMA) Then
strAVMAId = objProduct.IAID
If strAVMAId <> "" And Not IsNull(strAVMAId) Then
LineOut findar("L_MsgAVMAID") & strAVMAId
Else
LineOut findar("L_MsgAVMAID") & findar("L_MsgNotAvailable")
End If
DisplayAVMAClientInformation objProduct
End If
'We should stop processing if we aren't processing All and either we were told to process a single
'entry only or we found the primary SKU
If strParm <> "all" Then
If (strParm = LCase(strSLActID)) Then
Exit For 'no need to continue
End If
End If
LineOut ""
End If
Next
If productKeyFound = False Then
LineOut findar("L_MsgErrorPKey")
End If
End Sub
Private Function GetDaysFromMins(iMins)
Dim iMinsInADay
iMinsInADay = 24 * 60
' VBScript only supports Int truncation or 'evens' rounding, it does not support a CEILING/FLOOR operation or MOD
' To simulate the CEILING operation used for other grace-day calculations in the UX we need to add the # of mins
' in a day minus 1 to the input then divide by the mins in a day
GetDaysFromMins = Int((iMins + iMinsInADay - 1) / iMinsInADay)
End Function
Private Sub InstallProductKey(strProductKey)
Dim objService, objProduct
Dim lRet, strDescription, strOutput, strVersion
Dim iIsPrimaryWindowsSku, bIsKMS
bIsKMS = False
On Error Resume Next
set objService = GetServiceObject("Version")
strVersion = objService.Version
objService.InstallProductKey(strProductKey)
QuitIfError()
' Installing a product key could change Windows licensing state.
' Since the service determines if it can shut down and when is the next start time
' based on the licensing state we should reconsume the licenses here.
objService.RefreshLicenseStatus()
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause, PartialProductKeyNonNullWhereClause)
strDescription = objProduct.Description
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
If IsKmsServer(strDescription) Then
bIsKMS = True
Exit For
End If
Next
If (bIsKMS = True) Then
' Set the KMS version in the registry (64 and 32 bit versions)
lRet = SetRegistryStr(HKEY_LOCAL_MACHINE, SLKeyPath, "KeyManagementServiceVersion", strVersion)
If (lRet <> 0) Then
QuitWithError lRet
End If
If ExistsRegistryKey(HKEY_LOCAL_MACHINE, SLKeyPath32) Then
lRet = SetRegistryStr(HKEY_LOCAL_MACHINE, SLKeyPath32, "KeyManagementServiceVersion", strVersion)
If (lRet <> 0) Then
QuitWithError lRet
End If
End If
Else
' Clear the KMS version in the registry (64 and 32 bit versions)
lRet = DeleteRegistryValue(HKEY_LOCAL_MACHINE, SLKeyPath, "KeyManagementServiceVersion")
If (lRet <> 0 And lRet <> 2 And lRet <> 5) Then
QuitWithError lRet
End If
lRet = DeleteRegistryValue(HKEY_LOCAL_MACHINE, SLKeyPath32, "KeyManagementServiceVersion")
If (lRet <> 0 And lRet <> 2 And lRet <> 5) Then
QuitWithError lRet
End If
End If
strOutput = Replace(findar("L_MsgInstalledPKey"), "%PKEY%", strProductKey)
LineOut strOutput
End Sub
Private Sub OutputIndeterminateOperationWarning(objProduct)
Dim strOutput
LineOut findar("L_MsgUndeterminedPrimaryKeyOperation")
strOutput = Replace(findar("L_MsgUndeterminedOperationFormat"), "%PRODUCTDESCRIPTION%", objProduct.Description)
strOutput = Replace(strOutput, "%PRODUCTID%", objProduct.ID)
LineOut strOutput
End Sub
Private Sub ClearPKeyFromRegistry()
Dim objService
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
objService.ClearProductKeyFromRegistry()
QuitIfError()
LineOut findar("L_MsgClearedPKey")
End Sub
Private Sub InstallLicenseFiles (strParentDirectory, fso)
Dim file, files, folder, subFolder
Set folder = fso.GetFolder(strParentDirectory)
Set files = folder.Files
' Install all license files in folder
For Each file In files
If Right(file.Name, 7) = ".xrm-ms" Then
InstallLicense strParentDirectory & "\" & file.Name
End If
Next
For Each subFolder in folder.SubFolders
InstallLicenseFiles subFolder, fso
Next
End Sub
Private Sub ReinstallLicenses()
Dim shell, fso, strOemFolder
Dim strSppTokensFolder, folder, subFolder
Set shell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strOemFolder = shell.ExpandEnvironmentStrings("%SystemRoot%") & "\system32\oem"
strSppTokensFolder = shell.ExpandEnvironmentStrings("%SystemRoot%") & "\system32\spp\tokens"
LineOut findar("L_MsgReinstallingLicenses")
Set folder = fso.GetFolder(strSppTokensFolder)
For Each subFolder in folder.SubFolders
InstallLicenseFiles subFolder, fso
Next
If (fso.FolderExists(strOemFolder)) Then
InstallLicenseFiles strOemFolder, fso
End If
LineOut findar("L_MsgLicensesReinstalled")
End Sub
Private Sub ReArmWindows
Dim objService
set objService = GetServiceObject("Version")
On Error Resume Next
objService.ReArmWindows()
QuitIfError()
LineOut findar("L_MsgRearm_1")
LineOut findar("L_MsgRearm_2")
End Sub
Private Sub ReArmApp(strSLID)
Dim objService
set objService = GetServiceObject("Version")
QuitIfError()
objService.ReArmApp(strSLID)
QuitIfError()
LineOut findar("L_MsgRearm_1")
End Sub
Private Sub ReArmSku(strSLID)
Dim objProductIter
Dim strSLActID
Dim strWhereClause
Dim bSkuFound
strSLID = LCase(strSLID)
bSkuFound = False
strWhereClause = "ID = '" & strSLID & "'"
For Each objProductIter in GetProductCollection("ID", strWhereClause)
strSLActID = objProductIter.ID
If (strSLID = LCase(strSLActID)) Then
bSkuFound = True
objProductIter.ReArmsku()
QuitIfError()
LineOut findar("L_MsgRearm_1")
Exit For
End If
Next
If (bSkuFound = False) Then
LineOut findar("L_MsgErrorProductNotFound")
End If
End Sub
Private Sub ExpirationDatime(strActivationID)
Dim strWhereClause
Dim objProduct
Dim strSLActID, ls, graceRemaining, strEnds
Dim strOutput
Dim strDescription, bTBL, bAVMA
Dim iIsPrimaryWindowsSku
Dim bFound
strActivationID = LCase(strActivationID)
bFound = False
If strActivationId = "" Then
strWhereClause = "ApplicationId = '" & WindowsAppId & "'"
Else
strWhereClause = "ID = '" & Replace(strActivationID, "'", "") & "'"
End If
strWhereClause = strWhereClause & " AND " & PartialProductKeyNonNullWhereClause
For Each objProduct in GetProductCollection(ProductIsPrimarySkuSelectClause & ", LicenseStatus, GracePeriodRemaining", strWhereClause)
strSLActID = objProduct.ID
ls = objProduct.LicenseStatus
graceRemaining = objProduct.GracePeriodRemaining
strEnds = DateAdd("n", graceRemaining, Now)
bFound = True
iIsPrimaryWindowsSku = GetIsPrimaryWindowsSKU(objProduct)
If (strActivationID = "") And (iIsPrimaryWindowsSku = 2) Then
OutputIndeterminateOperationWarning(objProduct)
End If
strOutput = ""
If ls = 0 Then
strOutput = findar("L_MsgLicenseStatusUnlicensed")
ElseIf ls = 1 Then
If graceRemaining <> 0 Then
strDescription = objProduct.Description
bTBL = IsTBL(strDescription)
bAVMA = IsAVMA(strDescription)
If bTBL Then
strOutput = Replace(findar("L_MsgLicenseStatusTBL"), "%ENDDATE%", strEnds)
ElseIf bAVMA Then
strOutput = Replace(findar("L_MsgLicenseStatusAVMA"), "%ENDDATE%", strEnds)
Else
strOutput = Replace(findar("L_MsgLicenseStatusVL"), "%ENDDATE%", strEnds)
End If
Else
strOutput = findar("L_MsgLicenseStatusLicensed")
End If
ElseIf ls = 2 Then
strOutput = Replace(findar("L_MsgLicenseStatusInitialGrace"), "%ENDDATE%", strEnds)
ElseIf ls = 3 Then
strOutput = Replace(findar("L_MsgLicenseStatusAdditionalGrace"), "%ENDDATE%", strEnds)
ElseIf ls = 4 Then
strOutput = Replace(findar("L_MsgLicenseStatusNonGenuineGrace"), "%ENDDATE%", strEnds)
ElseIf ls = 5 Then
strOutput = findar("L_MsgLicenseStatusNotification")
ElseIf ls = 6 Then
strOutput = Replace(findar("L_MsgLicenseStatusExtendedGrace"), "%ENDDATE%", strEnds)
End If
If strOutput <> "" Then
LineOut objProduct.Name & ":"
Lineout " " & strOutput
End If
Next
If True <> bFound Then
LineOut findar("L_MsgErrorPKey")
End If
End Sub
'' Volume license service/client management
Private Sub QuitIfErrorRestoreKmsName(obj, strKmsName)
Dim objErr
If Err.Number <> 0 Then
set objErr = new CErr
If strKmsName = "" Then
obj.ClearKeyManagementServiceMachine()
Else
obj.SetKeyManagementServiceMachine(strKmsName)
End If
ShowError findar("L_MsgErrorText_8"), objErr
ExitScript objErr.Number
End If
End Sub
Private Function GetKmsClientObjectByActivationID(strActivationID)
Dim objProduct, objTarget
strActivationID = LCase(strActivationID)
Set objTarget = Nothing
On Error Resume Next
If strActivationID = "" Then
Set objTarget = GetServiceObject("Version, " & KMSClientLookupClause)
QuitIfError()
Else
For Each objProduct in GetProductCollection("ID, " & KMSClientLookupClause, EmptyWhereClause)
If (LCase(objProduct.ID) = strActivationID) Then
Set objTarget = objProduct
Exit For
End If
Next
If objTarget is Nothing Then
Lineout Replace(findar("L_MsgErrorActivationID"), "%ActID%", strActivationID)
End If
End If
Set GetKmsClientObjectByActivationID = objTarget
End Function
Private Sub SetKmsMachineName(strKmsNamePort, strActivationID)
Dim objTarget
Dim nColon, strKmsName, strKmsNamePrev, strKmsPort, nBracketEnd
Dim nKmsPort
nBracketEnd = InStr(StrKmsNamePort, "]")
If InStr(strKmsNamePort, "[") = 1 And nBracketEnd > 1 Then
' IPV6 Address
If Len(StrKmsNamePort) = nBracketEnd Then
'No Port Number
strKmsName = strKmsNamePort
strKmsPort = ""
Else
strKmsName = Left(strKmsNamePort, nBracketEnd)
strKmsPort = Right(strKmsNamePort, Len(strKmsNamePort) - nBracketEnd - 1)
End If
Else
' IPV4 Address
nColon = InStr(1, strKmsNamePort, ":")
If nColon <> 0 Then
strKmsName = Left(strKmsNamePort, nColon - 1)
strKmsPort = Right(strKmsNamePort, Len(strKmsNamePort) - nColon)
Else
strKmsName = strKmsNamePort
strKmsPort = ""
End If
End If
Set objTarget = GetKmsClientObjectByActivationID(strActivationID)
On Error Resume Next
If Not objTarget is Nothing Then
strKmsNamePrev = objTarget.KeyManagementServiceMachine
If strKmsName <> "" Then
objTarget.SetKeyManagementServiceMachine(strKmsName)
QuitIfError()
End If
If strKmsPort <> "" Then
nKmsPort = CLng(strKmsPort)
QuitIfErrorRestoreKmsName objTarget, strKmsNamePrev
objTarget.SetKeyManagementServicePort(nKmsPort)
QuitIfErrorRestoreKmsName objTarget, strKmsNamePrev
Else
objTarget.ClearKeyManagementServicePort()
QuitIfErrorRestoreKmsName objTarget, strKmsNamePrev
End If
LineOut Replace(findar("L_MsgKmsNameSet"), "%KMS%", strKmsNamePort)
If objTarget.KeyManagementServiceLookupDomain <> "" Then
LineOut Replace(findar("L_MsgKmsUseMachineNameOverrides"), _
"%KMS%", _
strKmsNamePort)
End If
End If
End Sub
Private Sub ClearKms(strActivationID)
Dim objTarget
Set objTarget = GetKmsClientObjectByActivationID(strActivationID)
On Error Resume Next
If Not objTarget is Nothing Then
objTarget.ClearKeyManagementServiceMachine()
QuitIfError()
objTarget.ClearKeyManagementServicePort()
QuitIfError()
LineOut findar("L_MsgKmsNameCleared")
If objTarget.KeyManagementServiceLookupDomain <> "" Then
LineOut Replace(findar("L_MsgKmsUseLookupDomain"), _
"%FQDN%", _
objTarget.KeyManagementServiceLookupDomain)
End If
End If
End Sub
Private Sub SetKmsLookupDomain(strKmsLookupDomain, strActivationID)
Dim objTarget
Dim strKms, nPort
Set objTarget = GetKmsClientObjectByActivationID(strActivationID)
On Error Resume Next
If Not objTarget is Nothing Then
objTarget.SetKeyManagementServiceLookupDomain(strKmsLookupDomain)
QuitIfError()
LineOut Replace(findar("L_MsgKmsLookupDomainSet"), "%FQDN%", strKmsLookupDomain)
If objTarget.KeyManagementServiceMachine <> "" Then
strKms = objTarget.KeyManagementServiceMachine
nPort = objTarget.KeyManagementServicePort
LineOut Replace(findar("L_MsgKmsUseMachineNameOverrides"), _
"%KMS%", strKms & ":" & nPort)
End If
End If
End Sub
Private Sub ClearKmsLookupDomain(strActivationID)
Dim objTarget
Dim strKms, nPort
Set objTarget = GetKmsClientObjectByActivationID(strActivationID)
On Error Resume Next
If Not objTarget is Nothing Then
objTarget.ClearKeyManagementServiceLookupDomain
QuitIfError()
LineOut findar("L_MsgKmsLookupDomainCleared")
If objTarget.KeyManagementServiceMachine <> "" Then
strKms = objTarget.KeyManagementServiceMachine
nPort = objTarget.KeyManagementServicePort
LineOut Replace(findar("L_MsgKmsUseMachineName"), _
"%KMS%", strKms & ":" & nPort)
End If
End If
End Sub
Private Sub SetHostCachingDisable(boolHostCaching)
Dim objService
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
objService.DisableKeyManagementServiceHostCaching(boolHostCaching)
QuitIfError()
If boolHostCaching Then
LineOut findar("L_MsgKmsHostCachingDisabled")
Else
LineOut findar("L_MsgKmsHostCachingEnabled")
End If
End Sub
Private Sub SetActivationInterval(intInterval)
Dim objService, objProduct
Dim kmsFlag, strOutput
If (intInterval < 0) Then
LineOut findar("L_MsgInvalidDataError")
Exit Sub
End If
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
For Each objProduct in GetProductCollection("ID, IsKeyManagementServiceMachine", PartialProductKeyNonNullWhereClause)
kmsFlag = objProduct.IsKeyManagementServiceMachine
If kmsFlag = 1 Then
objService.SetVLActivationInterval(intInterval)
QuitIfError()
strOutput = Replace(findar("L_MsgActivationSet"), "%ACTIVATION%", intInterval)
LineOut strOutput
LineOut findar("L_MsgWarningKmsReboot")
Exit For
End If
Next
If kmsFlag <> 1 Then
LineOut findar("L_MsgWarningActivation")
End If
End Sub
Private Sub SetRenewalInterval(intInterval)
Dim objService, objProduct
Dim kmsFlag, strOutput
If (intInterval < 0) Then
LineOut findar("L_MsgInvalidDataError")
Exit Sub
End If
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
For Each objProduct in GetProductCollection("ID, IsKeyManagementServiceMachine", PartialProductKeyNonNullWhereClause)
kmsFlag = objProduct.IsKeyManagementServiceMachine
If kmsFlag Then
objService.SetVLRenewalInterval(intInterval)
QuitIfError()
strOutput = Replace(findar("L_MsgRenewalSet"), "%RENEWAL%", intInterval)
LineOut strOutput
LineOut findar("L_MsgWarningKmsReboot")
Exit For
End If
Next
If kmsFlag <> 1 Then
LineOut findar("L_MsgWarningRenewal")
End If
End Sub
Private Sub SetKmsListenPort(strPort)
Dim objService, objProduct
Dim kmsFlag, lRet, strOutput
Dim nPort
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
For Each objProduct in GetProductCollection("ID, IsKeyManagementServiceMachine", PartialProductKeyNonNullWhereClause)
kmsFlag = objProduct.IsKeyManagementServiceMachine
If kmsFlag Then
nPort = CLng(strPort)
objService.SetKeyManagementServiceListeningPort(nPort)
QuitIfError()
strOutput = Replace(findar("L_MsgKmsPortSet"), "%PORT%", strPort)
LineOut strOutput
LineOut findar("L_MsgWarningKmsReboot")
Exit For
End If
Next
If kmsFlag <> 1 Then
LineOut findar("L_MsgWarningKmsPort")
End If
End Sub
Private Sub SetDnsPublishingDisabled(bool)
Dim objService, objProduct
Dim kmsFlag, lRet, dwValue
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
For Each objProduct in GetProductCollection("ID, IsKeyManagementServiceMachine", PartialProductKeyNonNullWhereClause)
kmsFlag = objProduct.IsKeyManagementServiceMachine
If kmsFlag Then
objService.DisableKeyManagementServiceDnsPublishing(bool)
QuitIfError()
If bool Then
LineOut findar("L_MsgKmsDnsPublishingDisabled")
Else
LineOut findar("L_MsgKmsDnsPublishingEnabled")
End If
LineOut findar("L_MsgWarningKmsReboot")
Exit For
End If
Next
If kmsFlag <> 1 Then
LineOut findar("L_MsgKmsDnsPublishingWarning")
End If
End Sub
Private Sub SetKmsLowPriority(bool)
Dim objService, objProduct
Dim kmsFlag, lRet, dwValue
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
For Each objProduct in GetProductCollection("ID, IsKeyManagementServiceMachine", PartialProductKeyNonNullWhereClause)
kmsFlag = objProduct.IsKeyManagementServiceMachine
If kmsFlag Then
objService.EnableKeyManagementServiceLowPriority(bool)
QuitIfError()
If bool Then
LineOut findar("L_MsgKmsPriSetToLow")
Else
LineOut findar("L_MsgKmsPriSetToNormal")
End If
LineOut findar("L_MsgWarningKmsReboot")
End If
Exit For
Next
If kmsFlag <> 1 Then
LineOut findar("L_MsgWarningKmsPri")
End If
End Sub
Private Sub SetVLActivationType(intType, strActivationID)
Dim objTarget
If IsNull(intType) Then
intType = 0
End If
If (intType < 0) Or (intType > 3) Then
LineOut findar("L_MsgInvalidDataError")
Exit Sub
End If
Set objTarget = GetKmsClientObjectByActivationID(strActivationID)
On Error Resume Next
If Not objTarget is Nothing Then
If (intType <> 0) Then
objTarget.SetVLActivationTypeEnabled(intType)
QuitIfError()
Else
objTarget.ClearVLActivationTypeEnabled()
QuitIfError()
End If
LineOut findar("L_MsgVLActivationTypeSet")
End If
End Sub
'' Token-based Activation Commands
Private Function IsTokenActivated(objProduct)
Dim nILVID
On Error Resume Next
nILVID = objProduct.TokenActivationILVID
IsTokenActivated = ((Err.Number = 0) And (nILVID <> &HFFFFFFFF))
End Function
Private Sub TkaListILs
Dim objLicense
Dim strHeader
Dim strError
Dim strGuids
Dim arrGuids
Dim nListed
Dim objWmiDate
LineOut findar("L_MsgTkaLicenses")
LineOut ""
Set objWmiDate = CreateObject("WBemScripting.SWbemDateTime")
nListed = 0
For Each objLicense in g_objWMIService.InstancesOf(TkaLicenseClass)
strHeader = findar("L_MsgTkaLicenseHeader")
strHeader = Replace(strHeader, "%ILID%" , objLicense.ILID )
strHeader = Replace(strHeader, "%ILVID%", objLicense.ILVID)
LineOut strHeader
LineOut " " & Replace(findar("L_MsgTkaLicenseILID"), "%ILID%", objLicense.ILID)
LineOut " " & Replace(findar("L_MsgTkaLicenseILVID"), "%ILVID%", objLicense.ILVID)
If Not IsNull(objLicense.ExpirationDate) Then
objWmiDate.Value = objLicense.ExpirationDate
If (objWmiDate.GetFileTime(false) <> 0) Then
LineOut " " & Replace(findar("L_MsgTkaLicenseExpiration"), "%TODATE%", objWmiDate.GetVarDate)
End If
End If
If Not IsNull(objLicense.AdditionalInfo) Then
LineOut " " & Replace(findar("L_MsgTkaLicenseAdditionalInfo"), "%MOREINFO%", objLicense.AdditionalInfo)
End If
If Not IsNull(objLicense.AuthorizationStatus) And _
objLicense.AuthorizationStatus <> 0 _
Then
strError = CStr(Hex(objLicense.AuthorizationStatus))
LineOut " " & Replace(findar("L_MsgTkaLicenseAuthZStatus"), "%ERRCODE%", strError)
Else
LineOut " " & Replace(findar("L_MsgTkaLicenseDescr"), "%DESC%", objLicense.Description)
End If
LineOut ""
nListed = nListed + 1
Next
if 0 = nListed Then
LineOut findar("L_MsgTkaLicenseNone")
End If
End Sub
Private Sub TkaRemoveIL(strILID, strILVID)
Dim objLicense
Dim strMsg
Dim nRemoved
Dim nILVID
On Error Resume Next
nILVID = CInt(strILVID)
QuitIfError()
LineOut findar("L_MsgTkaRemoving")
LineOut ""
nRemoved = 0
For Each objLicense in g_objWMIService.InstancesOf(TkaLicenseClass)
If strILID = objLicense.ILID And nILVID = objLicense.ILVID Then
strMsg = findar("L_MsgTkaRemovedItem")
strMsg = Replace(strMsg, "%SLID%", objLicense.ID)
On Error Resume Next
objLicense.Uninstall
QuitIfError()
LineOut strMsg
nRemoved = nRemoved + 1
End If
Next
If nRemoved = 0 Then
LineOut findar("L_MsgTkaRemovedNone")
End If
End Sub
Private Sub TkaListCerts
Dim objProduct
Dim objSigner
Dim iRet
Dim arrGrants()
Dim arrThumbprints
Dim strThumbprint
On Error Resume Next
Set objSigner = TkaGetSigner()
Set objProduct = TkaGetProduct()
iRet = objProduct.GetTokenActivationGrants(arrGrants)
QuitIfError()
arrThumbprints = objSigner.GetCertificateThumbprints(arrGrants)
QuitIfError()
For Each strThumbprint in arrThumbprints
TkaPrintCertificate strThumbprint
Next
End Sub
Private Sub TkaActivate(strThumbprint, strPin)
Dim objService
Dim objProduct
Dim objSigner
Dim iRet
Dim strChallenge
Dim strAuthInfo1
Dim strAuthInfo2
Set objSigner = TkaGetSigner()
Set objProduct = TkaGetProduct()
Set objService = TkaGetService()
DisplayActivatingSku objProduct
On Error Resume Next
iRet = objProduct.GenerateTokenActivationChallenge(strChallenge)
QuitIfError()
strAuthInfo1 = objSigner.Sign(strChallenge, strThumbprint, strPin, strAuthInfo2)
QuitIfError()
iRet = objProduct.DepositTokenActivationResponse(strChallenge, strAuthInfo1, strAuthInfo2)
QuitIfError()
objService.RefreshLicenseStatus()
Err.Number = 0
objProduct.refresh_
DisplayActivatedStatus objProduct
QuitIfError()
End Sub
Private Function TkaGetService()
Set TkaGetService = GetServiceObject("Version")
End Function
Private Function TkaGetProduct()
Dim objWinProductsWithPKeyInstalled
Dim objProduct
On Error Resume Next
Set TkaGetProduct = Nothing
Set TkaGetProduct = GetProductObject( _
"ID, Name, ApplicationId, PartialProductKey, Description, LicenseIsAddon ", _
"ApplicationId = '" & WindowsAppId & "' " &_
"AND PartialProductKey <> NULL " & _
"AND LicenseIsAddon = FALSE" _
)
QuitIfError()
End Function
Private Function TkaGetSigner()
On Error Resume Next
Set TkaGetSigner = WScript.CreateObject("SPPWMI.SppWmiTokenActivationSigner")
QuitIfError()
End Function
Private Sub TkaPrintCertificate(strThumbprint)
Dim arrParams
arrParams = Split(strThumbprint, "|")
LineOut ""
LineOut Replace(findar("L_MsgTkaCertThumbprint"), "%THUMBPRINT%", arrParams(0))
LineOut Replace(findar("L_MsgTkaCertSubject" ), "%SUBJECT%" , arrParams(1))
LineOut Replace(findar("L_MsgTkaCertIssuer" ), "%ISSUER%" , arrParams(2))
LineOut Replace(findar("L_MsgTkaCertValidFrom" ), "%FROMDATE%" , FormatDateTime(CDate(arrParams(3)), vbShortDate))
LineOut Replace(findar("L_MsgTkaCertValidTo" ), "%TODATE%" , FormatDateTime(CDate(arrParams(4)), vbShortDate))
End Sub
'' Active Directory Activation Commands
Private Function IsADActivated(objProduct)
On Error Resume Next
If (objProduct.VLActivationType = 1) Then
IsADActivated = True
Else
IsADActivated = False
End If
End Function
Private Sub ADActivateOnline(strProductKey, strActivationObjectName)
Dim objService
FailRemoteExec()
On Error Resume Next
set objService = GetServiceObject("Version")
QuitIfError()
objService.DoActiveDirectoryOnlineActivation strProductKey, strActivationObjectName
QuitIfError()
LineOut findar("L_MsgActivated")
End Sub
Private Sub ADGetIID(strProductKey)
Dim objService
Dim strIID
FailRemoteExec()
On Error Resume Next
set objService = GetServiceObject("Version")
objService.GenerateActiveDirectoryOfflineActivationId strProductKey, strIID
QuitIfError()
LineOut findar("L_MsgInstallationID") & strIID
LineOut ""
LineOut findar("L_MsgPhoneNumbers")
End Sub
Private Sub ADActivatePhone(strProductKey, strCID, strActivationObjectName)
Dim objService
Dim strIID
FailRemoteExec()
On Error Resume Next
set objService = GetServiceObject("Version")
objService.DepositActiveDirectoryOfflineActivationConfirmation strProductKey, strCID, strActivationObjectName
QuitIfError()
LineOut findar("L_MsgActivated")
End Sub
Private Sub ADListActivationObjects()
Dim machineDomain
Dim namespace
Dim rootDSE, configurationNC
Dim container, child
Dim found
FailRemoteExec()
On Error Resume Next
' Fetch computer's domain name. This must be used while querying for
' Activation Objects to ensure we do not query them from current user's
' domain (which may be in a different forest than computer's domain).
machineDomain = GetMachineDomain()
QuitIfError()
set namespace = GetObject(ADLdapProvider)
QuitIfError()
set rootDSE = namespace.OpenDSObject(ADLdapProviderPrefix & machineDomain & ADRootDSE, vbNullString, vbNullString, ADS_READOtrombonistaY_SERVER)
QuitIfError()
configurationNC = rootDSE.Get(ADConfigurationNC)
QuitIfError()
set container = namespace.OpenDSObject(ADLdapProviderPrefix & machineDomain & ADActObjContainer & configurationNC, vbNullString, vbNullString, ADS_READOtrombonistaY_SERVER)
If Err.Number = HR_ERROR_DS_NO_SUCH_OBJECT Then
LineOut findar("L_MsgADSchemaNotSupported")
Exit Sub
End If
QuitIfError()
LineOut findar("L_MsgActObjAvailable")
found = False
For Each child in container
If child.Class = ADActObjClass Then
found = True
child.GetInfoEx Array(ADActObjDisplayName, ADActObjAttribDN, ADActObjAttribSkuId, ADActObjAttribPid), 0
LineOut " " & findar("L_MsgADInfoAOName") & child.Get(ADActObjDisplayName)
LineOut " " & " " & findar("L_MsgActID") & GuidToString(child.Get(ADActObjAttribSkuId))
LineOut " " & " " & findar("L_MsgPartialPKey") & child.Get(ADActObjAttribPartialPkey)
LineOut " " & " " & findar("L_MsgADInfoExtendedPid") & child.Get(ADActObjAttribPid)
LineOut " " & " " & findar("L_MsgADInfoAODN") & child.Get(ADActObjAttribDN)
LineOut ""
End If
Next
If (found = False) Then
LineOut " " & findar("L_MsgActObjNoneFound")
End If
End Sub
Private Sub ADDeleteActivationObjects(strName)
Dim machineDomain
Dim namespace
Dim rootDSE, configurationNC
Dim container, strDN
Dim object, parent
FailRemoteExec()
On Error Resume Next
machineDomain = GetMachineDomain()
QuitIfError()
set namespace = GetObject(ADLdapProvider)
QuitIfError()
set rootDSE = GetObject(ADLdapProviderPrefix & machineDomain & ADRootDSE)
QuitIfError()
configurationNC = rootDSE.Get(ADConfigurationNC)
QuitIfError()
' Check if AD schema supports Activation Objects containers
set container = namespace.OpenDSObject(ADLdapProviderPrefix & machineDomain & ADActObjContainer & configurationNC, vbNullString, vbNullString, ADS_READOtrombonistaY_SERVER)
If Err.Number = HR_ERROR_DS_NO_SUCH_OBJECT Then
LineOut findar("L_MsgADSchemaNotSupported")
Exit Sub
End If
QuitIfError()
If InStr(1, strName, ",cn=", vbTextCompare) > 0 Then
strDN = strName
Else
'
' RDN was provided. Construct a full DN from it.
'
' Use computer's domain name to construct the Activation Object DN.
If 1 = InStr(1, strName, "cn=", vbTextCompare) Then
strDN = strName & "," & ADActObjContainer & configurationNC
Else
strDN = "CN=" & strName & "," & ADActObjContainer & configurationNC
End If
LineOut " " & findar("L_MsgADInfoAODN") & strDN
LineOut ""
End If
set object = GetObject(ADLdapProviderPrefix & strDN)
QuitIfError()
set parent = GetObject(object.Parent)
QuitIfError()
If (object.Class = ADActObjClass) Then
parent.Delete object.Class, object.Name
QuitIfError()
End If
LineOut findar("L_MsgSucess")
End Sub
' other generic options/helpers
Private Sub LineOut(str)
g_EchoString = g_EchoString & str & falena
End Sub
Private Sub LineFlush(str)
WScript.Echo g_EchoString & str
g_EchoString = ""
End Sub
Private Sub ExitScript(retval)
if (g_EchoString <> "") Then
WScript.Echo g_EchoString
End If
WScript.Quit retval
End Sub
Function GetMachineDomain()
Dim adSystemInfo
Dim machineDomain
set adSystemInfo = CreateObject("ADSystemInfo")
QuitIfError()
machineDomain = adSystemInfo.DomainDNSName & "/"
QuitIfError()
GetMachineDomain = machineDomain
End Function
Function HexByte(b)
HexByte = Right("0" & Hex(b), 2)
End Function
Function GuidToString(ByteArray)
Dim Binary, S
Binary = CStr(ByteArray)
S = "{"
S = S & HexByte(AscB(MidB(Binary, 4, 1)))
S = S & HexByte(AscB(MidB(Binary, 3, 1)))
S = S & HexByte(AscB(MidB(Binary, 2, 1)))
S = S & HexByte(AscB(MidB(Binary, 1, 1)))
S = S & "-"
S = S & HexByte(AscB(MidB(Binary, 6, 1)))
S = S & HexByte(AscB(MidB(Binary, 5, 1)))
S = S & "-"
S = S & HexByte(AscB(MidB(Binary, 8, 1)))
S = S & HexByte(AscB(MidB(Binary, 7, 1)))
S = S & "-"
S = S & HexByte(AscB(MidB(Binary, 9, 1)))
S = S & HexByte(AscB(MidB(Binary, 10, 1)))
S = S & "-"
S = S & HexByte(AscB(MidB(Binary, 11, 1)))
S = S & HexByte(AscB(MidB(Binary, 12, 1)))
S = S & HexByte(AscB(MidB(Binary, 13, 1)))
S = S & HexByte(AscB(MidB(Binary, 14, 1)))
S = S & HexByte(AscB(MidB(Binary, 15, 1)))
S = S & HexByte(AscB(MidB(Binary, 16, 1)))
S = S & "}"
GuidToString = S
End Function
Private Sub InstallLicense(licFile)
Dim objService
Dim LicenseData
Dim strOutput
On Error Resume Next
LicenseData = ReadAllTextFile(licFile)
QuitIfError()
set objService = GetServiceObject("Version")
QuitIfError()
objService.InstallLicense(LicenseData)
QuitIfError()
strOutput = Replace(findar("L_MsgLicenseFile"), "%LICENSEFILE%", licFile)
LineOut strOutput
LineOut ""
End Sub
' Returns the encoding for a givven file.
' Possible return values: ascii, unicode, unicodeFFFE (big-endian), utf-8
Function GetFileEncoding(strFileName)
Dim strData
Dim strEncoding
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1 'adTypeBinary
oStream.Open
oStream.LoadFromFile(strFileName)
' Default encoding is ascii
strEncoding = "ascii"
strData = BinaryToString(oStream.Read(2))
' Check for little endian (x86) unicode preamble
If (Len(strData) = 2) and strData = (Chr(255) + Chr(254)) Then
strEncoding = "unicode"
Else
oStream.Position = 0
strData = BinaryToString(oStream.Read(3))
' Check for utf-8 preamble
If (Len(strData) >= 3) and strData = (Chr(239) + Chr(187) + Chr(191)) Then
strEncoding = "utf-8"
End If
End If
oStream.Close
GetFileEncoding = strEncoding
End Function
' Converts binary data (VT_UI1 | VT_ARRAY) to a string (BSTR)
Function BinaryToString(dataBinary)
Dim i
Dim str
For i = 1 To LenB(dataBinary)
str = str & Chr(AscB(MidB(dataBinary, i, 1)))
Next
BinaryToString = str
End Function
' Returns string containing the whole text file data.
' Supports ascii, unicode (little-endian) and utf-8 encoding.
Function ReadAllTextFile(strFileName)
Dim strData
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 2 'adTypeText
oStream.Open
oStream.Charset = GetFileEncoding(strFileName)
oStream.LoadFromFile(strFileName)
strData = oStream.ReadText(-1) 'adReadAll
oStream.Close
ReadAllTextFile = strData
End Function
Private Function HandleOptionParam(cParam, mustProvide, opt, param)
Dim strOutput
HandleOptionParam = True
If WScript.Arguments.Count <= cParam Then
HandleOptionParam = False
If mustProvide Then
LineOut ""
strOutput = Replace(findar("L_MsgErrorText_9"), "%OPTION%", opt)
strOutput = Replace(strOutput, "%PARAM%", param)
LineOut strOutput
Call DisplayUsage()
End If
End If
End Function
' A Copy of Err from the point of origin
Class CErr
Public Number
Public Description
Public Source
Private Sub Class_Initialize
Number = Err.Number
Description = Err.Description
Source = Err.Source
End Sub
End Class
Function NewCErr(number, source, description)
Dim objError
Set objError = new CErr
objError.Number = CLng(number)
objError.Source = source
objError.Description = description
Set NewCErr = objError
End Function
Private Sub ShowError(ByVal strMessage, ByVal objErr)
Dim strDescription
Dim strNumber
' Convert error number to text. Use hexadecimal format for negative values such as HRESULT errors.
If objErr.Number >= 0 Then
strNumber = CStr(objErr.Number)
Else
strNumber = "0x" & Hex(objErr.Number)
End If
strDescription = findar("L_MsgError_" & Hex(objErr.Number))
If strDescription = "" Then
If objErr.Description = "" Then
strDescription = Replace(findar("L_MsgErrorText_6"), "0x%ERRCODE%", strNumber)
ElseIf objErr.Source = "" Then
strDescription = objErr.Description
Else
strDescription = objErr.Description & " (" & objErr.Source & ")"
End If
End If
If 0 = InStr(strMessage, "0x%ERRCODE%") Then
strMessage = strMessage & "0x%ERRCODE%"
End If
If 0 = InStr(strMessage, "%ERRTEXT%") Then
strMessage = strMessage & " %ERRTEXT%"
End If
strMessage = Replace(strMessage, "%COMPUTERNAME%", g_strComputer)
strMessage = Replace(strMessage, "0x%ERRCODE%", strNumber)
strMessage = Replace(strMessage, "%ERRTEXT%", strDescription)
LineOut strMessage
End Sub
Private Sub QuitIfError()
QuitIfError2 "L_MsgErrorText_8"
End Sub
Private Sub QuitIfError2(strMessage)
Dim objErr
If Err.Number <> 0 Then
Set objErr = new CErr
ShowError findar(strMessage), objErr
ExitScript objErr.Number
End If
End Sub
Private Sub QuitWithError(errNum)
ShowError findar("L_MsgErrorText_8"), NewCErr(errNum, Empty, Empty)
ExitScript errNum
End Sub
Private Sub Connect
Dim objLocator, strOutput
Dim objServer, objService
Dim strErr, strVersion
On Error Resume Next
'If this is the local computer, set everything and return immediately
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")
QuitIfError2("L_MsgErrorLocalRegistry")
Exit Sub
End If
'Otherwise, establish the remote object connections
' Create Locator object to connect to remote CIM object manager
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
QuitIfError2("L_MsgErrorWMI")
' Connect to the namespace which is either local or remote
Set g_objWMIService = objLocator.ConnectServer (g_strComputer, "\root\cimv2", g_strUserName, g_strPassword)
QuitIfError2("L_MsgErrorConnection")
g_IsRemoteComputer = True
g_objWMIService.Security_.impersonationlevel = wbemImpersonationLevelImpersonate
QuitIfError2("L_MsgErrorImpersonation")
g_objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
QuitIfError2("L_MsgErrorAuthenticationLevel")
' Get the SPP service version on the remote machine
set objService = GetServiceObject("Version")
strVersion = objService.Version
' The Windows 8 version of SLMgr.vbs does not support remote connections to Vista/WS08 and Windows 7/WS08R2 machines
if (Not IsNull(strVersion)) Then
strVersion = Left(strVersion, 3)
If (strVersion = "6.0") Or (strVersion = "6.1") Then
LineOut findar("L_MsgRemoteWmiVersionMismatch")
ExitScript 1
End If
End If
Set objServer = objLocator.ConnectServer(g_strComputer, "\root\default:StdRegProv", g_strUserName, g_strPassword)
QuitIfError2("L_MsgErrorConnectionRegistry")
objServer.Security_.ImpersonationLevel = 3
Set g_objRegistry = objServer.Get("StdRegProv")
QuitIfError2("L_MsgErrorConnectionRegistry")
End Sub
Function GetServiceObject(strQuery)
Dim objService
Dim colServices
On Error Resume Next
Set colServices = g_objWMIService.ExecQuery("SELECT " & strQuery & " FROM " & ServiceClass)
QuitIfError()
For each objService in colServices
QuitIfError()
Exit For
Next
QuitIfError()
set GetServiceObject = objService
End Function
Function GetProductCollection(strSelect, strWhere)
Dim colProducts
Dim objProduct
On Error Resume Next
If strWhere = EmptyWhereClause Then
Set colProducts = g_objWMIService.ExecQuery("SELECT " & strSelect & " FROM " & ProductClass)
QuitIfError()
Else
Set colProducts = g_objWMIService.ExecQuery("SELECT " & strSelect & " FROM " & ProductClass & " WHERE " & strWhere)
QuitIfError()
End If
For each objProduct in colProducts
Next
QuitIfError()
set GetProductCollection = colProducts
End Function
Function GetProductObject(strSelect, strWhere)
Dim objProduct
Dim colProducts
Dim iProductsFound
On Error Resume Next
iProductsFound = 0
Set colProducts = GetProductCollection(strSelect, strWhere)
For each objProduct in colProducts
QuitIfError()
iProductsFound = iProductsFound + 1
Next
'There should be exactly one product returned by the query. If there are none
'assume the product key and/or licenses are missing. If there are more than one
'then fail with invalid arguments.
If iProductsFound = 0 Then
LineOut findar("L_MsgErrorPKey")
Err.Number = HR_SL_E_PKEY_NOT_INSTALLED
ElseIf iProductsFound <> 1 Then
Err.Number = HR_INVALID_ARG
End If
QuitIfError()
'Return the first (and only) element in the collection
For each objProduct in colProducts
QuitIfError()
Exit For
Next
set GetProductObject = objProduct
End Function
Private Function IsKmsClient(strDescription)
If InStr(strDescription, "VOLUME_KMSCLIENT") > 0 Then
IsKmsClient = True
Else
IsKmsClient = False
End If
End Function
Private Function IsTkaClient(strDescription)
IsTkaClient = IsKmsClient(strDescription)
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
Antivirus Signature
Bkav Clean
Lionic Clean
tehtris Clean
ClamAV Clean
CMC Clean
CAT-QuickHeal Clean
Skyhigh BehavesLike.VBS.Dropper.cv
ALYac Clean
Malwarebytes Clean
Zillya Clean
Sangfor Clean
K7AntiVirus Clean
K7GW Clean
Cybereason Clean
Baidu Clean
VirIT Clean
Symantec Scr.Guloader!gen3
ESET-NOD32 Clean
TrendMicro-HouseCall Clean
Avast Clean
Cynet Clean
Kaspersky HEUR:Trojan.Script.Generic
BitDefender Clean
NANO-Antivirus Clean
ViRobot Clean
MicroWorld-eScan Clean
Tencent Clean
TACHYON Clean
Sophos Clean
F-Secure Clean
DrWeb Clean
VIPRE Clean
TrendMicro Clean
FireEye Clean
Emsisoft Clean
huorong Clean
GData Clean
Jiangmin Clean
Varist Clean
Avira Clean
Antiy-AVL Clean
Kingsoft Script.Dropper.vbs.2023281
Gridinsoft Clean
Xcitium Clean
Arcabit Clean
SUPERAntiSpyware Clean
ZoneAlarm Clean
Microsoft Clean
Google Clean
AhnLab-V3 Clean
Acronis Clean
McAfee Clean
MAX Clean
VBA32 Clean
Zoner Clean
Rising Clean
Yandex Clean
Ikarus Clean
MaxSecure Clean
Fortinet Clean
BitDefenderTheta Clean
AVG Clean
Panda Clean
CrowdStrike Clean
alibabacloud Clean
No IRMA results available.