使用WMI和VBSCRIPT检查TPM准备情况

时间:2014-08-08 17:52:12

标签: vbscript wmi tpm

如果我使用此WMI method '.IsEnabled',我应该关注我在if语句中处理结果的方式。如果方法返回bool值,我仍然可以使用Not或者我应该使用

if myStatus <> 0 OR isTPMEnabled <> True then

这是我的代码

function isTPMReadyToBeOwned(myTPMService)
        dim myStatus, isTPMEnabled, isTPMActivated, isTPMOwnershipAllowed

        myStatus = myTPMService.IsEnabled(isTPMEnabled)
        if myStatus <> 0 or not(isTPMEnabled) then
            oLogging.CreateEntry "TPM isn't enable and must be enabled and activated manually, errorcode " & Hex(myStatus), LogTypeWarning
            isTPMReadyToBeOwned = False
            exit Function
        end If

        myStatus = myTPMService.IsActivated(isTPMActivated)
        If myStatus <> 0 or not(isTPMActivated) then
            oLogging.CreateEntry "TPM isn't active and must be activated manually, errorcode " & Hex(myStatus), LogTypeWarning
            isTPMReadyToBeOwned = False
            exit Function
        end If

        myStatus = myTPMService.isOwnershipAllowed(isTPMOwnershipAllowed)
        if myStatus <> 0 or not(isTPMOwnershipAllowed) then 
            oLogging.CreateEntry "TPM ownership is not allowed, errorcode " & Hex(myStatus), LogTypeWarning
            isTPMReadyToBeOwned = False
            exit Function
        end If

        isTPMReadyToBeOwned = True
    end Function

1 个答案:

答案 0 :(得分:0)

不应将布尔表达式/变量与布尔文字进行比较,因为它会增加额外的复杂度(运算符和操作数)。所以使用Not isTPMEnabled。由于Not既不是函数也不是数组,不要使用param list / index(); reserve()用于优先覆盖的情况。

更新评论:

()在VBScript中也有很多函数

  1. 函数调用中的参数列表():x = f(y,z)
  2. index():a = SomeArray(4711)
  3. 优先权覆盖:2 + 3 * 4 = 14,(2 + 3)* 5 = 25
  4. 布尔表达式中的

    ()只能是类型3。