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

Re: error handling permissions denied by Pegasus

Pegasus
Mon Jul 14 13:14:23 CDT 2008


"floyd" <w> wrote in message
news:487b8cbe$0$76916$dbd49001@news.wanadoo.nl...
> 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
>

Which is the line of code that causes the problem?



Re: error handling permissions denied by floyd

floyd
Mon Jul 14 13:47:51 CDT 2008

The problem is when the script make a connection to the computer when the
computer is online.
The script give me a permission denied, but other xp computers i have no
problem with the script.


"Pegasus (MVP)" <I.can@fly.com.oz> schreef in bericht
news:e6ASy1d5IHA.4908@TK2MSFTNGP04.phx.gbl...
>
> "floyd" <w> wrote in message
> news:487b8cbe$0$76916$dbd49001@news.wanadoo.nl...
>> 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
>>
>
> Which is the line of code that causes the problem?
>



Re: error handling permissions denied by Pegasus

Pegasus
Mon Jul 14 15:32:57 CDT 2008


"floyd" <w> wrote in message
news:487b9d40$0$49400$dbd49001@news.wanadoo.nl...
> The problem is when the script make a connection to the computer when the
> computer is online.
> The script give me a permission denied, but other xp computers i have no
> problem with the script.

There are several places where access problems can occur.
Remove the line "On error resume next", then report in your
reply which line throws up the error.



Re: error handling permissions denied by floyd

floyd
Mon Jul 14 16:25:58 CDT 2008

Ok tommorow at work i give you a reply which line throws up the error

"Pegasus (MVP)" <I.can@fly.com.oz> schreef in bericht
news:eJb8ODf5IHA.3932@TK2MSFTNGP04.phx.gbl...
>
> "floyd" <w> wrote in message
> news:487b9d40$0$49400$dbd49001@news.wanadoo.nl...
>> The problem is when the script make a connection to the computer when the
>> computer is online.
>> The script give me a permission denied, but other xp computers i have no
>> problem with the script.
>
> There are several places where access problems can occur.
> Remove the line "On error resume next", then report in your
> reply which line throws up the error.
>



Re: error handling permissions denied by floyd

floyd
Tue Jul 15 10:43:18 CDT 2008

On this line i get a error :

Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' "
etc etc ...

The error is : microsoft Vbscript runtime error : Permissions Denied:
'GetObject'

When i make a network mapping to this computer, i get a access denied, i
have not so much rights, for this computer.
But the script stoppped, other computers works fine in the domain.
The script runs with domain admin rights.

Is there a way that the script goes to the next computer.


floyd







"floyd" <w> schreef in bericht
news:487bc24c$0$99248$dbd4d001@news.wanadoo.nl...
> Ok tommorow at work i give you a reply which line throws up the error
>
> "Pegasus (MVP)" <I.can@fly.com.oz> schreef in bericht
> news:eJb8ODf5IHA.3932@TK2MSFTNGP04.phx.gbl...
>>
>> "floyd" <w> wrote in message
>> news:487b9d40$0$49400$dbd49001@news.wanadoo.nl...
>>> The problem is when the script make a connection to the computer when
>>> the computer is online.
>>> The script give me a permission denied, but other xp computers i have
>>> no problem with the script.
>>
>> There are several places where access problems can occur.
>> Remove the line "On error resume next", then report in your
>> reply which line throws up the error.
>>
>
>



Re: error handling permissions denied by Pegasus

Pegasus
Tue Jul 15 10:44:24 CDT 2008


"floyd" <w> wrote in message
news:487cc37c$0$38197$dbd4b001@news.wanadoo.nl...
> On this line i get a error :
>
> Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
> SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' "
> etc etc ...
>
> The error is : microsoft Vbscript runtime error : Permissions Denied:
> 'GetObject'
>
> When i make a network mapping to this computer, i get a access denied, i
> have not so much rights, for this computer.
> But the script stoppped, other computers works fine in the domain.
> The script runs with domain admin rights.
>
> Is there a way that the script goes to the next computer.
>

This code will do it:
on error resume next
Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' "
on error goto 0



Re: error handling permissions denied by floyd

floyd
Tue Jul 15 14:51:16 CDT 2008

thank you Pegasus


"Pegasus (MVP)" <I.can@fly.com.oz> schreef in bericht
news:O9JgoGp5IHA.5108@TK2MSFTNGP06.phx.gbl...
>
> "floyd" <w> wrote in message
> news:487cc37c$0$38197$dbd4b001@news.wanadoo.nl...
>> On this line i get a error :
>>
>> Set objWMIService = GetObject("winmgmts:\\" & strcomputer &
>> "\root\CIMV2")
>> SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' "
>> etc etc ...
>>
>> The error is : microsoft Vbscript runtime error : Permissions
>> Denied: 'GetObject'
>>
>> When i make a network mapping to this computer, i get a access denied, i
>> have not so much rights, for this computer.
>> But the script stoppped, other computers works fine in the domain.
>> The script runs with domain admin rights.
>>
>> Is there a way that the script goes to the next computer.
>>
>
> This code will do it:
> on error resume next
> Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
> SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' "
> on error goto 0
>
>