VBscript从事件ID获取事件的属性 [英] VBscript to get the properties of event from event ID

查看:171
本文介绍了VBscript从事件ID获取事件的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用vbscript从事件ID 4624获取机器的IP,登录用户,主机名?



我想要一个vbscript取出这些信息:

解决方案

这是可能的。您需要使用事件日志中的ID 4624查询事件,然后从消息字符串中解析出名称,IP地址和端口,例如。使用正则表达式:

 设置wmi = GetObject(winmgmts://./root/cimv2)

Set re = New RegExp
re.Pattern =网络信息:\s +& _
工作站名称:\s *(。*?)\s +& _
源网络地址:\s *(。*?)\s +& _
源端口:\s *(\d +)

qry =SELECT * FROM Win32_NTLogEvent WHERE EventCode = 4624
对于每个evt在wmi.ExecQuery (qry)
对于每个m在re.Execute(evt.Message)
hostname = m.SubMatches(0)
address = m.SubMatches(1)
port = m .SubMatches(2)
下一个
WScript.Echo hostname& [&地址& :&港口& ]
下一个


I want to know if it is possible to get the IP of machine, logged on user, hostname from event id 4624 using vbscript?

I want a vbscript which takes out this information:

解决方案

It's possible. You need to query events with the ID 4624 from the eventlog and then parse name, IP address and port out of the message string, e.g. with a regular expression:

Set wmi = GetObject("winmgmts://./root/cimv2")

Set re = New RegExp
re.Pattern = "Network Information:\s+" & _
             "Workstation Name:\s*(.*?)\s+" & _
             "Source Network Address:\s*(.*?)\s+" & _
             "Source Port:\s*(\d+)"

qry = "SELECT * FROM Win32_NTLogEvent WHERE EventCode=4624"
For Each evt In wmi.ExecQuery(qry)
  For Each m In re.Execute(evt.Message)
    hostname = m.SubMatches(0)
    address  = m.SubMatches(1)
    port     = m.SubMatches(2)
  Next
  WScript.Echo hostname & " [" & address & ":" & port & "]"
Next

这篇关于VBscript从事件ID获取事件的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆