Windows 在VBScript中提取事件安全日志不会返回任何值

Windows 在VBScript中提取事件安全日志不会返回任何值,windows,vbscript,wmi,Windows,Vbscript,Wmi,下面是我试图用于从Windows事件日志文件提取信息的代码之一: Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Security)}!\\" & "." & "\root\cimv2") Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent where LogF

下面是我试图用于从Windows事件日志文件提取信息的代码之一:

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\\" & "." & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent where LogFile='Application'")
WScript.Echo "Application Log Count:" & colEvents.count
Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent where LogFile='System'")
WScript.Echo "System Log Count:" & colEvents.count
Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent where LogFile='Security'")
WScript.Echo "Security Log Count:" & colEvents.count
我的问题是,这只能访问“应用程序”和“系统”日志文件,而不能访问“安全”日志文件。即使我使用这组代码:

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Security)}!\\" & "." & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile")
For Each objLogFile in colLogFiles
    Wscript.Echo objLogFile.name
Next

Output:

C:\Windows\System32\Winevt\Logs\Application.evtx
C:\Windows\System32\Winevt\Logs\HardwareEvents.evtx
C:\Windows\System32\Winevt\Logs\Internet Explorer.evtx
C:\Windows\System32\Winevt\Logs\Key Management Service.evtx
C:\Windows\System32\Winevt\Logs\Lenovo-Customer Feedback.evtx
C:\Windows\System32\Winevt\Logs\OAlerts.evtx
C:\Windows\System32\Winevt\Logs\PreEmptive.evtx
C:\Windows\System32\Winevt\Logs\Reason.evtx
C:\Windows\System32\Winevt\Logs\System.evtx
C:\Windows\System32\Winevt\Logs\Windows PowerShell.evtx

安全文件仍不包括在内。我使用的是Windows10机器。我使用WMI尝试了所有其他代码,但仍然无法访问安全日志文件。“我的安全事件”可通过事件查看器查看,并有数千条记录。

除非您在提升的会话中以管理员身份运行代码,否则系统将不允许您读取
安全事件日志。尝试执行
wevtutil gl security
谢谢。以管理员的身份运行!