|
AspEventViewer Component - freeLast updated: 01/20/98, Refresh (4/7/98 Initial Release) If you are long-time fan of our site, you may know about the EventLog ISAPI extension we were providing to read the event log entries online. This ISAPI extension has been converted to a component that can be used in ASP scripts or for "normal" server information gathering from for example Microsoft Excel. The AspEventViewer component sports all functionality you need to read all three different sources (System, Security and Application) on your local computer as well as any remote computer. Additionally to the functionality of reading the event log, you can also use the component to delete the event log entries. The API is limited to only a few functions (pseudo-code below): bool OpenLog(machine, source) bool CloseLog() bool ClearLog(machine, source) long GetFirst() long GetNext(eventId, eventType, eventSource, eventDate) bool GetRecord(nRecordNo, eventId, eventType, eventSource, _ eventDate,computername, accountname,error-description) First of all, you have to open the event log (OpenLog), then you can access entries either via GetRecord (please notice that the accountname return value currently is not implemented!) or iterating over all entries using GetFirst() and GetNext(). Included with the downloadable component are examples for scripting these functions (a shortened version is shown below). SamplesSample 1: Iterating over the Application Log<% nMaxRecs = 100 Set x = CreateObject("Softwing.EventLogReader") retval = x.OpenLog(vbNullChar, "Application") n = x.GetFirst() nPrevious = n %> <TABLE BORDER=0> <TR> <TH ALIGN=LEFT></TH><TH ALIGN=LEFT>Date</TH><TH ALIGN=LEFT>Time</TH> <TH ALIGN=LEFT>Source</TH><TH ALIGN=LEFT>Event ID</TH> </TR> <% While nMaxRecs > 0 n = x.GetNext(EvId, EvType, strEvSource, EvDate) WriteIcon EvType nPrevious = n Response.Write "</TD><TD>" & FormatDateTime(EvDate,2) Response.Write "</TD><TD>" & FormatDateTime(EvDate,3) Response.Write "</TD><TD>" & strEvSource & "</TD><TD>" & EvId Response.Write "</TD></TR>" & vbCRLF nMaxRecs = nMaxRecs - 1 Wend %> </TABLE> <% retval = x.CloseLog() %> <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER"> sub WriteIcon(nEvType) Response.Write "<IMG WIDTH=16 HEIGT=15 BORDER=0 SRC=""" select case nEvType case EVENTLOG_SUCCESS Response.Write "asuccess" case EVENTLOG_ERROR_TYPE Response.Write "error" case EVENTLOG_WARNING_TYPE Response.Write "warning" case EVENTLOG_INFORMATION_TYPE Response.Write "info" case EVENTLOG_AUDIT_SUCCESS Response.Write "afail" case EVENTLOG_AUDIT_FAILURE Response.Write "asuccess" end select Response.Write ".gif"">" End Sub </SCRIPT> Sample 2: Displaying a Single Record<% Set x = CreateObject("Softwing.EventLogReader") retval = x.OpenLog(vbNullChar, "Application") nRecord = Trim(Request.QueryString("Id")) retval = x.GetRecord(nRecord, EvId, EvType, strSource, _ EvDate, strComputer, strAccount, strDesc) %> <TABLE width="95%" BORDER=0 cellspacing=2> <TR> <TH ALIGN=LEFT>Date</TH><TD><%=FormatDateTime(EvDate,2)%></TD> <TH ALIGN=LEFT>Event ID</TH><TD><%=EvId%></TD> </TR><TR> <TH ALIGN=LEFT>Time</TH><TD><%=FormatDateTime(EvDate,3)%></TD> <TH ALIGN=LEFT>Source</TH><TD><%=strSource%></TD> </TR><TR> <TH ALIGN=LEFT>User</TH><TD></TD> <TH ALIGN=LEFT>Type</TH><TD><%WriteIcon EvType%></TD> </TR><TR> <TH ALIGN=LEFT>Computer</TH><TD><%=strComputer%></TD> <TH ALIGN=LEFT>Category</TH><TD></TD> </TR><TR> <TH ALIGN=LEFT colspan=4>Description:</TH> </TR><TR> <TD colspan=4><%=strDesc%></TD> </TR></TABLE> <% retval = x.CloseLog() %> Installation and DownloadBefore using the component you have to register it using the regsvr32 utility: regsvr32 evviewer.dll. Download (size is approx. 80KB) If you do have any questions, please feel free to send mail to Christoph Wille. |
All content and images on this site are copyright. Reuse (even parts) needs our written consent. |