Can somebody help me with this script.
I want to check windows xp machines is the computer online or not, then the
script will check of there is some events in de eventviewer
for disk bad blocks. ( this is not the hole script )
But by some computers i have an access denied (Code Error 800A0046 -
Permission Denied ) ,
the script stopped. also with On Error Resume Next.
Is there a way that the script will run the next computer?
Thanks for help
Floyd
Here is the script :
On Error Resume Next
Const ForReading = 1
Const FOR_WRITING = 2
Const ForAppending = 8
'///// Open the input file
Dim oFSO, oTF, oShell
Set oFSO = CreateObject("scripting.filesystemobject")
Set oTF = oFSO.OpenTextFile("computers.txt",ForReading,True)
Set oShell = CreateObject("Wscript.Shell")
'///// Creer input en output file`s
Dim sLogfile : sLogFile = "output\computer_SYSTEM.log"
Dim sLogFile1 : sLogFile1 = "input\computer_NOK.txt"
Dim sLogFile2 : sLogFile2 = "input\computer_OK.txt"
Dim sLogFile3 : sLogFile3 = "input\Inventory_DiskBadBlocks.txt"
Do While oTF.AtEndOfStream <> True
IntConnectionError = 0
strComputer = oTF.ReadLine
'///// Ping computer
Dim objShell , objExec , strPingResults
Dim objWMIService , colCompSystems , objCompSystem
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
WScript.Echo VbCrLf & strComputer & " is online"
Dim oLogFile1 : Set oLogFile1 = oFSO.OpenTextFile
(sLogFile2,FOR_WRITING,true)
oLogFile1.WriteLine strcomputer
Dim colItems
Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' AND
TimeGenerated >""" + sDate + """"
Set colItems = objWMIService.ExecQuery (SqlQuery)
Dim oLogFile3 : Set oLogFile3 = oFSO.OpenTextFile
(sLogFile3,ForAppending,true)
Dim intEvent,objEvent
intEvent = 0
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objEvent in colItems
If objEvent.EventCode = "7" Then
If objevent.sourcename = "Disk" then
intEvent = intEvent + 1
'F_WriteLogFile WMIDateStringToDate(objEvent.TimeGenerated) & "
|Bad Blocks op Cdrom of Disk " & objevent.sourcename , sLogFile
End If
End If
Next
If intEvent > 1 then
F_WriteLogFile "Event Disk Bad Blocks " & intEvent & " " &
strcomputer & " <<<<<" , sLogFile
oLogFile3.WriteLine strcomputer & " " & date & " Aantal: " &
intevent
Else
F_WriteLogFile "Event Disk Bad Blocks " & intEvent
, sLogFile
End If
WScript.Echo VbCrLf & strComputer & " is not online"
Dim oLogFile : Set oLogFile = oFSO.OpenTextFile (sLogFile1,FOR_WRITING,true)
oLogFile.WriteLine strcomputer
End If
Loop