【问题标题】:Checking for TPM readiness with WMI and VBSCRIPT使用 WMI 和 VBSCRIPT 检查 TPM 准备情况
【发布时间】:2014-08-08 17:52:12
【问题描述】:

如果我使用这个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

【问题讨论】:

    标签: vbscript wmi tpm


    【解决方案1】:

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

    更新评论:

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

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

    () 只能是类型 3。

    【讨论】:

    • 不明白你的最后一句话,“不要使用参数列表/索引();保留()用于优先覆盖的情况。”
    猜你喜欢
    • 2010-11-25
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多