Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Automatically clear and save event logs

Automatically clear and save event logs

Automatically clear and save event logs


I am looking for a way to automatically clear and save the event logs to a file server.

Has anyone come across a tool to do this? Or has anyone done this in the past?

Any help appreciated.



RE: Automatically clear and save event logs

Yup, I have a script that does it.

Save the code to a text file and name it DumpEventLogs.vbs
then schedule the script to run at whatever interval you see fit.  Don't forget to edit the destination path.


' NAME: DumpEventLogs.vbs
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor    
' URL: http://www.thespidersparlor.com
' DATE  : 1/12/2004
' COMMENT: Edit the Destination Server path below to indicate where to dump files to.  
'          Run this script on the server who's event logs are to be saved.
' This script and many more are included in
'               The Spider's Parlor Admin Script Pack

Dim DestServer
' Put in the UNC path for where you want the logs to be stored

DestServer = "\\backupserver\C$\Logs\"

'Create the Time variables

sDate=Right("0" & Month(Date),2) _
& "-" & Right("0" & Day(Date),2) _
& "-" & Right(Year(Date),2)

sTime = DatePart("h", Now) & DatePart("n", Now)

set oFSO = CreateObject("Scripting.FileSystemObject")

'If correct folder doesn't exist, make it

if Not oFSO.FolderExists(DestServer & sDate) then
   set oFolder = oFSO.CreateFolder(DestServer & sDate )
end if

'Gets the log files for this machine

strComputer = "."

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

Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile")

'This section goes out and gets the hostname this is run on for us.

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

For Each objItem in colItems
  strHOSTNAME = objItem.Name

'Now archive the logs and clear them

if oFSO.FolderExists(DestServer & sDate) then
  For Each objLogfile in colLogFiles
    strBackupLog = objLogFile.BackupEventLog _
        (DestServer & sDate & "\"  & strHOSTNAME & "_" & objLogFile.LogFileName & "_" & sDate & "_" & sTime & ".evt")
end if

I hope you find this post helpful.  



RE: Automatically clear and save event logs

Thank you very much ******

RE: Automatically clear and save event logs

Just testing this on my home PC which runs XP. But I recieve an invalid character error at line 1.

Will it only run on 2003. Or do i need to install something for it to run?

RE: Automatically clear and save event logs

If line one is



Then you probably are missing the leading apostraphe from your copy/paste.  The apostraphe indicates the code after it is a comment.

I hope you find this post helpful.  



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close