Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBScript not running‏

Reply
 
Old 05-28-2008   #1 (permalink)
Mark


 
 

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 SpecsSystem Spec
Old 05-28-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: VBScript not running?


"Mark" <Mark@xxxxxx> wrote in message
newsCB66182-32AE-4727-BFEA-F52A0E6FF3A3@xxxxxx
Quote:

> '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.
What exactly do you mean with "not getting executed"? What happens
when you run it? Do you see any error messages? And what is the
script supposed to do?


My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46