【问题标题】:How to tell if Win32_NTLogEvent InsertionString exists?如何判断 Win32_NTLogEvent InsertionString 是否存在?
【发布时间】:2013-03-05 18:37:32
【问题描述】:

我创建了一个 VBScript 来显示我的系统日志内容。如果存在,我还想包括 InsertionString。但是,我似乎无法确定是否存在 InsertionString。这是我的脚本的开头:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set rs = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = 'System' and SourceName = 'mysource'")
For Each objEvent in rs
    If objEvent.InsertionString exists....

我尝试了几种变体来确定是否存在 InsertionString,但均未成功,包括:

If Not IsNull(objEvent.InsertionString) Then
If objEvent.InsertionString.Length > 0 Then
If GetLength(objEvent.InsertionString(1)) > 0 Then
If objEvent.InsertionString(1).Length > 0 Then

任何建议将不胜感激。

谢谢。

【问题讨论】:

    标签: windows events vbscript wmi


    【解决方案1】:

    您在属性名称中拼写错误 InsertionString 应该是 InsertionStrings。 所以这段代码可以正常工作

     If not IsNull(objEvent.InsertionStrings) Then
    

    注意:InsertionStrings 属性是一个字符串数组,因此您可以使用For Each 循环或UBoundLBound 函数迭代该属性。

    【讨论】:

    • LBound() 通常是相当无用的,因为在 VBScript 数组中下限总是 0。
    • @RRUZ,感谢您的回复。我在脚本中使用了 InsertionStrings,但在这里不小心写了 InsertionString。不幸的是 objEvent.InsertionStrings 总是 Not Null 无论是否有插入字符串。所以当我提到 objEvent.InsertionStrings(1) 我得到一个 Invalid Index 错误。
    • @Neilw,该数组是基于零索引的,因此请尝试使用 objEvent.InsertionStrings(0) 并使用 UBound 和 LBound 函数检查数组的边界。
    • @RRUZ,这似乎是票。谢谢!
    猜你喜欢
    • 2013-05-12
    • 2021-07-26
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 2010-12-30
    • 2011-07-14
    • 2023-03-19
    相关资源
    最近更新 更多