Error when run this vbs script.

Hi,

Error when run this vbs script.
I want a way to ignore if any machine is off or permission error and go to next machine.

Below are 2 scripts that i want to first ping check and go to next if Off

---------------------------
Windows Script Host
---------------------------
Script:      C:\Find All Drives.vbs
Line:      13
Char:      13
Error:      The remote server machine does not exist or is unavailable: 'GetObject'
Code:      800A01CE
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

And this script

Dim objWMI, colROM
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\CD-Rom_Report.txt")
SourceFile = "C:\Computers.txt"
arrPCs = Split(objFSO.OpenTextFile(SourceFile).ReadAll, vbNewLine)
For Each PC In arrPCs
  Set objWMI = GetObject("winmgmts:\\" & PC & "\root\CIMV2")
  Set colROM = objWMI.ExecQuery("Select * From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
  If colROM.Count > 0 Then objOutput.WriteLine PC & " has an enabled CD-ROM"
Next
objOutput.Close
Set objOutput = Nothing
Set objWMI = Nothing
Set objFSO = Nothing
Set colROM = Nothing

Can anyone help please

REgards
Sharath
'=====================
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("Comp.txt", 1, False)
strDetails = "Results:"
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      boolPinged = Ping(strComputer)
      If boolPinged = True Then
            strDetails = strDetails & VbCrLf & strComputer & ": "
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
            intCount = 0
            For Each objItem In colItems
                  Select Case objItem.DriveType
                        Case 1 strDriveType = "Drive could not be determined."
                        Case 2 strDriveType = "Removable Drive"
                        Case 3 strDriveType = "Local hard disk."
                        Case 4 strDriveType = "Network disk." 
                        Case 5 strDriveType = "Compact disk (CD)" 
                        Case 6 strDriveType = "RAM disk." 
                        Case Else strDriveType = "Drive type Problem."
                  End Select
                  strDetails = strDetails & objItem.Caption & " " & strDriveType & ";"
                  intCount = intCount + 1
            Next
            strDetails = strDetails & intCount & " drives"
      End If
Wend
 
strOutputFile = "C:\Drives.txt"
Set objOutputFile = objFSO.CreateTextFile(strOutputFile)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad " & objFSO.GetFile(strOutputFile).ShortPath, 1, False
 
Set objFSO = Nothing
Set objShell = Nothing
 
Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'================

Open in new window

LVL 11
bsharathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi Sharath, try this.  The Ping was already there, the I have added error trapping on the GetObject call, and also added the CD Rom check.

Regards,

Rob.
'=====================
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("Comp.txt", 1, False)
strDetails = "Results:"
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      boolPinged = Ping(strComputer)
      If boolPinged = True Then
            strDetails = strDetails & VbCrLf & strComputer & ": "
            On Error Resume Next
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
			If Err.Number = 0 Then
				On Error GoTo 0
	            intCount = 0
	            For Each objItem In colItems
	                  Select Case objItem.DriveType
	                        Case 1 strDriveType = "Drive could not be determined."
	                        Case 2 strDriveType = "Removable Drive"
	                        Case 3 strDriveType = "Local hard disk."
	                        Case 4 strDriveType = "Network disk." 
	                        Case 5 strDriveType = "Compact disk (CD)" 
	                        Case 6 strDriveType = "RAM disk." 
	                        Case Else strDriveType = "Drive type Problem."
	                  End Select
	                  strDetails = strDetails & objItem.Caption & " " & strDriveType & ";"
	                  intCount = intCount + 1
	            Next
	            strDetails = strDetails & intCount & " drives"
	            
				' Extra bit
				Set colROM = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where MediaType=11") 'MediaType 11 is a CD-ROM
				If colROM.Count > 0 Then strDetails = strDetails & VbCrLf & strComputer & " has an enabled CD-ROM"
 
	        Else
	        	Err.Clear
	        	On Error GoTo 0
	        End If
      End If
Wend
 
strOutputFile = "C:\Drives.txt"
Set objOutputFile = objFSO.CreateTextFile(strOutputFile)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad " & objFSO.GetFile(strOutputFile).ShortPath, 1, False
 
Set objFSO = Nothing
Set objShell = Nothing
 
Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'================

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bsharathAuthor Commented:
Hi Rob... Trying this now...

I sent you a mail today can you have a look at this please...
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24426812.html
0
bsharathAuthor Commented:
Thank U Rob...
:-)
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

bsharathAuthor Commented:
Thank U Rob...
:-)
0
bsharathAuthor Commented:
Hi Rob...
Just a remonder to the mail i sent you with the Q...'s
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.