如果我使用这个WMI方法'。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
布尔表达式/变量不应该与布尔文字进行比较,因为它增加了额外的复杂性(操作符和操作数)。所以用Not isTPMEnabled
。由于Not
既不是函数也不是数组,所以不要使用参数列表/index ();Reserve()用于优先级重写的情况。
更新wrt注释:
()在VBScript中有(太多)功能
- 函数调用参数列表():x = f(y, z)
- index (): a = SomeArray(4711) 优先级:2 + 3 * 4 = 14,(2 + 3)* 5 = 25
()在布尔表达式中只能是类型3