Hi Alexei,
I've managed to obtain this code:
var source = "System";
var strComputer = ".";
var objPath = "winmgmts:{impersonationLevel=impersonate}!\\\\"+strComputer+"\\root\\cimv2";
Log.Message("Object path: "+objPath);
var objWMIService = GetObject(objPath);
var logQuery = "SELECT * FROM Win32_NTLogEvent WHERE Logfile = '"+source+"'";
Log.Message("Log query: "+logQuery);
var colLoggedEvents = objWMIService.ExecQuery(logQuery);
Log.Message("Log: "+colLoggedEvents); //EMPTY???
for(objEvent in colLoggedEvents){
var out = "Category: "+objEvent.Category + " \n Computer Name: "+objEvent.ComputerName+" \n Event Code: "+objEvent.EventCode+" \n Message: "+objEvent.Message+" \n Record Number: "+objEvent.RecordNumber+" \n Source Name: "+objEvent.SourceName+" \n Time Written: "+objEvent.TimeWritten+" \n Event Type: "+objEvent.Type+" \n User: "+objEvent.User;
Log.Message(out);
}
This runs but it seems that
colLoggedEvents is empty and because of that it never enters the for loop.
Any ideas what I'm doing wrong?
Thanks.