1

如果我使用这个WMI 方法“.IsEnabled” ,我应该关心如何处理 if 语句中的结果。如果一个方法返回一个布尔值,我还能使用 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
4

1 回答 1

0

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

更新 wrt 评论:

() 在 VBScript 中有(太多)函数

  1. 函数调用中的参数列表():x = f(y,z)
  2. 索引():a = SomeArray(4711)
  3. 优先级覆盖:2 + 3 * 4 = 14, (2 + 3) * 5 = 25

布尔表达式中的 () 只能是类型 3。

于 2014-08-08T18:05:34.310 回答