How to read Event Viewer Information from Code Unit

ckndr47ckndr47 Member Posts: 100
Hello Everybody,

I have to read messages of EventViewer from my code unit; I dont have any ocx for that;

Please guide me in this regard. I have to complete that task in a very short time. So kindly help me out.

Thanks in Advance

Comments

  • pduckpduck Member Posts: 147
    Use WMI Querys. WMI can be easily developed by using the WMITools provided by Microsoft: http://www.microsoft.com/downloads/details.aspx?FamilyID=6430f853-1120-48db-8cc5-f2abdc3ed314&DisplayLang=en

    With the WMI CMI Studio you can create your SQL String, to get all Event Descriptions from one Application for example.

    Because I used the WMI Automation Server only in a Delphi Applications I cannot give you some Navision examples. But I think you must create some Automation Variables of the Type Microsoft WMI Scripting V1.2 Library and the needed Subtypes Locator, Services and Object Set.

    Maybe this Code Snippet could be helpful. I queries all events of the given Service.
    VAR
      aLoc          : ISWbemLocator;
      aSrv          : ISWbemServices;
      aObjSet       : ISWbemObjectSet;
      pEnum         : IEnumvarIANT;
     
      aLoc := CoSWbemLocator.Create;
      aSrv := aLoc.ConnectServer(cConfig.sWMI_Host,'',
                  cConfig.sWMI_User,cConfig.GetWMIPassword(),'','',0, nil);
      aSrv.Security_.ImpersonationLevel :=                    wbemImpersonationLevelImpersonate;
    
       aObjSet := aSrv.ExecQuery('SELECT EventType, Message,     
                                                 TimeGenerated, InsertionStrings 
                                                 FROM Win32_NTLogEvent WHERE  
                                                 Logfile="Application" AND 
                                                 SourceName="<Service Name>",
                                                 'WQL', wbemFlagReturnImmediately +  
                                                 wbemFlagForwardOnly, nil);
          pEnum := aObjSet.Get__NewEnum as IEnumvarIANT;
    

    The enumeration contains the Response, but I don't know how to handle this in Navision? Be careful that for WMI Querys on localhost any User and Password should be given if you have administrative rights.
Sign In or Register to comment.