![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBScript not running 'Date Format M = Month(Now) M1 = MonthName(M, False) Y = Year(Date) D = Date() D1 = DatePart("d", D) 'To Find hostname Set objNTInfo = CreateObject("WinNTSystemInfo") GetComputerName = lcase(objNTInfo.ComputerName) 'Create Folders Set objFSO = CreateObject("Scripting.FileSystemObject") If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName) Then objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName) Else Wscript.echo "Unable to create Folder" If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y ) Then objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y) Else Wscript.echo "Unable to create Folder" If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1) Then objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1) Else Wscript.echo "Unable to create Folder" End If End If End if 'Backup & Clear Event log strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Backup,security)}!\\" & _ strComputer & "\root\cimv2") Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='Security'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_Security.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='Application'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_Application.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='System'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_System.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='Microsoft Office Diagnostics'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_Microsoft_Office_Diagnostics.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='Internet Explorer'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_Internet_Explorer.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName ='Microsoft Office Sessions'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_Microsoft_Office_Sessions.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName='Directory Service'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_dir.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName='DNS Server'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_dns.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next Set colLogFiles = objWMIService.ExecQuery _ ("Select * from Win32_NTEventLogFile where LogFileName='File Replication Service'") For Each objLogfile in colLogFiles errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& GetComputerName & "_frs.evt") If errBackupLog <> 0 Then Wscript.echo "nothing" Else objLogFile.ClearEventLog() End If Next The above script was successfully getting executed for one month, after on the next month the script was not getting executed. kindly advice Thanks in advance. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBScript not running? "Mark" <Mark@xxxxxx> wrote in message news CB66182-32AE-4727-BFEA-F52A0E6FF3A3@xxxxxxQuote: > 'Date Format > M = Month(Now) > M1 = MonthName(M, False) > Y = Year(Date) > D = Date() > D1 = DatePart("d", D) > > 'To Find hostname > Set objNTInfo = CreateObject("WinNTSystemInfo") > GetComputerName = lcase(objNTInfo.ComputerName) > > 'Create Folders > Set objFSO = CreateObject("Scripting.FileSystemObject") > If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName) > Then > objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName) > Else > Wscript.echo "Unable to create Folder" > If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName & > "\" > & Y ) Then > objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName & "\" > & > Y) > Else > Wscript.echo "Unable to create Folder" > If not objFSO.FolderExists("\\chnwsora14\eventlog\" & GetComputerName & > "\" > & Y & "\" & M1) Then > objFSO.CreateFolder("\\chnwsora14\eventlog\" & GetComputerName & "\" > & > Y & "\" & M1) > Else > Wscript.echo "Unable to create Folder" > End If > End If > End if > > 'Backup & Clear Event log > > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate,(Backup,security)}!\\" & _ > strComputer & "\root\cimv2") > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName ='Security'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_Security.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName > ='Application'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_Application.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName ='System'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_System.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName ='Microsoft > Office Diagnostics'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_Microsoft_Office_Diagnostics.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName ='Internet > Explorer'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_Internet_Explorer.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName ='Microsoft > Office Sessions'") > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_Microsoft_Office_Sessions.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName='Directory > Service'") > > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_dir.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName='DNS Server'") > > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_dns.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > Set colLogFiles = objWMIService.ExecQuery _ > ("Select * from Win32_NTEventLogFile where LogFileName='File > Replication > Service'") > > For Each objLogfile in colLogFiles > errBackupLog = objLogFile.BackupEventLog("\\chnwsora14\eventlog\" & > GetComputerName & "\" & Y & "\" & M1 & "\" & D1 & M & Y & "_"& > GetComputerName & "_frs.evt") > If errBackupLog <> 0 Then > Wscript.echo "nothing" > Else > objLogFile.ClearEventLog() > End If > Next > > The above script was successfully getting executed for one month, after on > the next month the script was not getting executed. kindly advice > > Thanks in advance. when you run it? Do you see any error messages? And what is the script supposed to do? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| New to VBscript, Help please! | VB Script | |||
| Where is VBscript now? | VB Script | |||
| VBscript Help | VB Script | |||
| How to do No hang up VBScript (nohup for VBScript) | VB Script | |||
| vbscript and HTA help | VB Script | |||