Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy the event log to a cursor

Windows Scripting

How to copy the event log to a cursor

by  Mike Gagnon  Posted    (Edited  )
The following was tested on VFP8.0, windows XP and Windows Scriting 5.6 installed:

Code:
Local x
x = 1
Create Cursor eventlogs (categorie N(10),;
 nomordi c(20),Code N(10),Message m,;
 nRecno N(10),Source c(50),dateheure T,Type c(20),usager c(20))
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
 + "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colRetrievedEvents = loWMIService.ExecQuery ;
 ("Select * from Win32_NTLogEvent")
For Each loEvent In colRetrievedEvents
 Wait Window Transform(x) Nowait
 Insert Into eventlogs (categorie,nomordi,Code,Message,nRecno,;
  source,dateheure,Type,usager) Values
(loEvent.Category,loEvent.ComputerName,;

loEvent.EventCode,Transform(loEvent.Message),loEvent.RecordNumber,loEvent.So
urceName,;
  WMIDateStringToDate(loEvent.TimeWritten),
loEvent.Type,Transform(loEvent.User))
 x = x + 1
Next
Function WMIDateStringToDate(dtmDate)
WMIDateStringToDate = Ctot(Substr(dtmDate, 5, 2) + "/" + ;
 Substr(dtmDate, 7, 2) + "/" + Left(dtmDate, 4) ;
 + " " + Substr(dtmDate, 9, 2) + ":" + ;
 Substr(dtmDate, 11, 2) + ":" + Substr(dtmDate, ;
 13, 2))
Return WMIDateStringToDate
Endfunc

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top