我尝试使用 WMI -> Win32_NTEventlogFile 读取 Windows 事件日志。我使用工具“WMI Delphi Code Creator”中的示例代码(链接到 WMI 教程)
procedure TEventLogsForm.GetWin32_NTLogEventInfo;
const
WbemUser ='';
WbemPassword ='';
WbemComputer ='localhost';
wbemFlagForwardOnly = $00000020;
var
FSWbemLocator : OLEVariant;
FWMIService : OLEVariant;
FWbemObjectSet: OLEVariant;
FWbemObject : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_NTLogEvent Where Logfile="Application"','WQL',wbemFlagForwardOnly);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
try
// ????
if not VarIsNull(FWbemObject.Data) then
Showmessage(IntToStr(Integer(FWbemObject.Data)));// Array of Uint8
if not VarIsNull(FWbemObject.InsertionStrings) then
Showmessage(String(FWbemObject.InsertionStrings));
except
on E:Exception do
begin
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
end;
FWbemObject:=Unassigned;
end;
end;
我尝试读取参数“FWbemObject.Data”和“FWbemObject.InsertionStrings”。但我得到错误:类型的变体(Array Variant)无法转换为类型(OleStr)
如何读取/显示此参数?