General discussion

Locked

A scripting question

By vitalhostage ·
I am trying to write a script (of which I have written ooooh.......all of one so far...ie 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."
Else
objLogFile.ClearEventLog()
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)
objFile.Close
Set objFSO = CreatdObject("Scripting.FileSystemObject")
objFSO.MoveFile "d:\application.evt" , "e:\errorlogbackup\"
End If
Next

Many thanks in advance for help offered

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| 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:

http://cwashington.netreach.net/depo/view.asp?Index=690&ScriptType=vbscript

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

Good luck!
Rob

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums