How can I read the WMI parameters "Data" and "InsertionStrings"?
I am trying to read a Windows EventLog with WMI -> Win32_NTEventlogFile. I use the sample code from the Delphi WMI Code Creator tool ( link to the WMI tutorial )
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; I am trying to read the parameters "FWbemObject.Data" and "FWbemObject.InsertionStrings". But I get the error: Variant of type (Array Variant) cannot be converted to type (OleStr)
How to read / display these parameters?
According to the documentation found here , Data and InsertionString is an array of bytes / strings,
Below I used it to iterate them in a for loop, I donβt know if it makes sense, but you can use as an example to do whatever you need :).
procedure GetWin32_NTLogEventInfo; const WbemUser =''; WbemPassword =''; WbemComputer ='localhost'; wbemFlagForwardOnly = $00000020; var FSWbemLocator : OLEVariant; FWMIService : OLEVariant; FWbemObjectSet: OLEVariant; FWbemObject : OLEVariant; oEnum : IEnumvariant; iValue : LongWord; Insertion : array of String; Data : array of Byte; I: integer; 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 begin Data := FWbemObject.Data; for I:= VarArrayLowBound(data,1) to VarArrayHighBound(data,1) do Showmessage(IntToStr(Data[I]));// Array of Uint8 end; if not VarIsNull(FWbemObject.InsertionStrings) then begin Insertion := FWbemObject.InsertionStrings; for I:= VarArrayLowBound(Insertion,1) to VarArrayHighBound(Insertion,1) do Showmessage(Insertion[I]); end; except on E:Exception do begin MessageDlg(E.Message, mtError, [mbOK], 0); end; end; FWbemObject:=Unassigned; end; end; There are some examples in this link, but it is written in VB