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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup Security Event Log

Status
Not open for further replies.

BB69

MIS
Jun 23, 2003
37
US
Hello,

Is there a way to backup the Security event log? I have tried with the script below but it does not work. I get an access denied error. I am assuming I would need to pass a username and password in the script to access the security log but I don't know how to do that. Also, I would like have it save with a date format on each day without having to modify the script each time. E.g. secYYYYMMMdd.evt. I plan to use the scheduling service to backup the file each day.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Security'")

For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog("E:\test\VBscript\eventlog\security.evt")
If errBackupLog <> 0 Then
Wscript.Echo "The security event log could not be backed up."
End If
Next

Any help would be appreciated.

Thanks
Brian.
 
I found how add the date on the file.

dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay

and when saving the file use
errBackupLog = objLogFile.BackupEventLog("E:\test\VBscript\eventlog\sec" & strBackupName & .evt")

Also changing this line allows me to read information from the security log but I am still not able to save it.
impersonationLevel=impersonate,(security)

What am I missing to backup the log.

Brian.
 
I got it.

I had to change this line.
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup,security)}!\\" & _
strComputer & "\root\cimv2")


Also, on the line below I forgot a quotation mark.
errBackupLog = objLogFile.BackupEventLog("E:\test\VBscript\eventlog\sec" & strBackupName & ".evt")

Brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top