General discussion


A scripting question

By vitalhostage ·
I am trying to write a script (of which I have written ooooh.......all of one so this one) that backsup the Event log, clears it then moves it to another directory and renames it using the Date created FileSystemObject. I can get it to do the following

Backup the event log
Clear the event log
Move the Event log file to another directory

but I can't get it to rename it using the date it was created

I have pasted the code I have written so far

Any suggestions would be greatly appreciated

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfile in colLogFiles
errBackupLog = objLogFile.BackupEventLog("d:\application.evt")
If errBackupLog <> 0 Then
Wscript.Echo "The Application event log could not be backed up."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("d:\application.evt")
Set objReadFile = objFSO.datecreated("d:\application.evt", 1) strContents = objFSO.datecreated
strPath = "objFSO.datecreated"
strFileName = objFSO.GetTempName
strFullName = objFSO.BuildPath(strPath, strFileName)
Set objFile = objFSO.CreateFile(strFullName)
Set objFSO = CreatdObject("Scripting.FileSystemObject")
objFSO.MoveFile "d:\application.evt" , "e:\errorlogbackup\"
End If

Many thanks in advance for help offered

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

A scripting question

by rdunn In reply to A scripting question

I'm not sure if you want to re-invent the wheel - there are a bunch of scripts available online that will do very much what you want to do here. What I like to try is to find a script that does -almost- everything I want, and then tweak it for my own purposes.

Try this one:

It's a doozy, but it seems pretty thorough. Just check and do a search if this isn't quite what you want. Thisis a GREAT site for admin VBS scripts.

Good luck!

Related Discussions

Related Forums