![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | error handling permissions denied 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: error handling permissions denied "floyd" <w> wrote in message news:487b8cbe$0$76916$dbd49001@xxxxxx Quote: > 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 > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: error handling permissions denied 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@xxxxxx> schreef in bericht news:e6ASy1d5IHA.4908@xxxxxx Quote: > > "floyd" <w> wrote in message > news:487b8cbe$0$76916$dbd49001@xxxxxx Quote: >> 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? > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: error handling permissions denied "floyd" <w> wrote in message news:487b9d40$0$49400$dbd49001@xxxxxx Quote: > 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. Remove the line "On error resume next", then report in your reply which line throws up the error. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: error handling permissions denied Ok tommorow at work i give you a reply which line throws up the error "Pegasus (MVP)" <I.can@xxxxxx> schreef in bericht news:eJb8ODf5IHA.3932@xxxxxx Quote: > > "floyd" <w> wrote in message > news:487b9d40$0$49400$dbd49001@xxxxxx Quote: >> 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. > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: error handling permissions denied 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@xxxxxx Quote: > Ok tommorow at work i give you a reply which line throws up the error > > "Pegasus (MVP)" <I.can@xxxxxx> schreef in bericht > news:eJb8ODf5IHA.3932@xxxxxx Quote: >> >> "floyd" <w> wrote in message >> news:487b9d40$0$49400$dbd49001@xxxxxx Quote: >>> 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. >> > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: error handling permissions denied "floyd" <w> wrote in message news:487cc37c$0$38197$dbd4b001@xxxxxx Quote: > 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. > on error resume next Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2") SqlQuery = "Select * from Win32_NTLogEvent Where Logfile ='System' " on error goto 0 |
My System Specs![]() |
| | #8 (permalink) |
| | Re: error handling permissions denied thank you Pegasus "Pegasus (MVP)" <I.can@xxxxxx> schreef in bericht news:O9JgoGp5IHA.5108@xxxxxx Quote: > > "floyd" <w> wrote in message > news:487cc37c$0$38197$dbd4b001@xxxxxx Quote: >> 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 > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: error handling | VB Script | |||
| WMI Error Handling | PowerShell | |||
| Enum permissions - access denied | General Discussion | |||
| Error Handling | PowerShell | |||
| Access Denied (XP and Vista permissions issue) | Vista security | |||