[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Find all the cd and dvd drives on my network

Hi,

How can i find all the cd and dvd drives on my networ.
A script which can scan the file in which i have all the machine name.

Scan results
Machine name  CD   DVD
Machinename   Yes   NO
Machinename   Machine not pinging

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 4
  • 3
1 Solution
 
zoofanCommented:
Hi bsharath,

I WARN YOU THIS WILL TAKE A LONG TIME TO RUN.........................  test on a short list first!!!!

This will prompt for a pc list file containing your pc names should be formatted as follows

pcname1
pcanem2
pcname3

It will query each machine and return the cd/dvd model information for all optical drives in the pc.  Then save the results into a csv file "pcname,drivemodel,drivemodel" or "pcname,error response" that you can open in excel.

'===Start copy: getcdroms.vbs===
' ---------------------------------------------------------------'
' getcdroms.vbs
' 'Sample VBScript to query remote computers
' 'and return cdrom model information into csv file.
' ''Author Riley C. aka ZooFan
' '''Version 1.7 - August 2007
' ''''www.experts-exchange.com question ID: 22746064
' ---------------------------------------------------------------'
'
Option explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3 'FileObject Access Type
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 'FileObject Format Type
Dim strPcList
Dim arrPcnames()
Dim strResultsFile
Dim dte
Dim tme
Dim objFso
Dim objWshShell
Dim objPCnames
Dim objReadFile
Dim intLneCount
Dim objOutputFile
Dim strCurPath
Dim intPCLoop
Dim strReturn      
Dim strTestcon
      Set objFso = CreateObject("Scripting.FileSystemObject")
      Set objWshShell = WScript.CreateObject("WScript.Shell")
      strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
      strPcList = InputBox("Please enter the full path and file" & VbCrLf & "name of the file with the computer names.","Get cdrom drives.")
            'Test to make sure file exists if not exit script
            If Not objFso.FileExists(strPcList) Then
                  MsgBox "You must enter a valid full path and file name!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)
            Elseif strPcList = "" Then
                  MsgBox "You must enter a filename!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)               
            Else 'File exists continue
                                    dte = Replace(FormatDateTime(date(),vbshortdate),"/","-")
                                    tme = Replace(Replace(FormatDateTime(now(),vbLongtime),":","-")," ","")
                                          strResultsFile = strCurPath & "\" & tme & "_" & dte & ".csv"
                                                If objFSO.FileExists(strResultsFile) Then
                                                      ObjFSO.deleteFile(strResultsFile)
                                                Else
                                                      Set objOutputFile = objFso.CreateTextFile(strResultsFile)
                                                      objOutputFile.Close      
                                                End If
                                                MsgBox strResultsFile
                                    Set objPCnames = objFso.GetFile(strPcList)
                                    Set objReadFile = objPCnames.OpenAsTextStream(ForReading, TristateUseDefault)
                                          Do Until objReadFile.AtEndOfStream
                                                ReDim Preserve arrPCnames(intLneCount)
                                                arrPCnames(intLneCount) = objReadFile.ReadLine
                                                intLneCount = intLneCount + 1
                                          Loop
                                    objReadFile.Close
                                          Set objOutputFile = objFso.OpenTextFile(strResultsFile,ForWriting,TristateUseDefault)
                                          objOutputFile.WriteLine("Computer,,Drives")
                                                For intPCLoop = LBound(arrPCnames) To UBound(arrPCnames)
                                                      strTestcon = IsServerOn(arrPCnames(intPCLoop))
                                                      If strTestcon = "0" then                                                
                                                      strReturn = getcdrom(arrPCnames(intPCLoop))
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strReturn)
                                                      Else
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strTestcon)
                                                      End If
                                                Next
                                           objOutputFile.Close
                                           MsgBox("Script has completed")
                                    WScript.Quit
                        End If
Function IsServerOn(strserver)                        
      Dim Testme
      Dim intErr
      Dim strRegValue
      Dim strFileServer
      On Error Resume Next
            Set Testme = GetObject("winmgmts://" & strserver & "/root/cimv2")
                  Set strRegValue = GetObject("winmgmts://" & strserver & "/root/default:StdRegProv")
                        intErr = Err.Number
                        If intErr <> 0 Then
                              IsServerOn = Err.Description
                        Else
                              IsServerOn = "0"
                        End If
      On Error GoTo 0
End Function
Function getcdrom(strcomputer)
Dim GetWMIServices
Dim colItems
Dim getcd
Dim obj
                        Set GetWMIServices = GetObject("winmgmts:" _
                            & "{impersonationLevel=impersonate}!//" & strcomputer & "/root/cimv2")
                        Set colItems = GetWMIServices.ExecQuery("Select * from Win32_CDROMDrive")
                        For Each obj In colItems
                        getCD = obj.name
                        getcdrom = getcdrom & "," & getcd
                        Next
                        If getcdrom = "," then
                         getcdrom = "Error reading drive information"
                         End if
      Set GetWMIServices = Nothing
      Set colItems = Nothing
End Function

Function readtextfile(strTxtFile, arrname())
On Error Resume Next
      Dim intErr, intLines
      Dim objTxtLines, objReadFile,objFso      
            Set objFso = CreateObject("Scripting.FileSystemObject")
            Set objTxtLines = objFso.GetFile(strTxtFile)
            Set objReadFile = objTxtLines.OpenAsTextStream(ForReading, TristateUseDefault)
                  Do Until objReadFile.AtEndOfStream
                        ReDim Preserve arrname(intLines)
                        arrname(intLines) = objReadFile.ReadLine
                        intLines = intLines + 1
                  Loop
            objReadFile.Close
            Set objFso = nothing
            Set objTxtLines = Nothing
            Set objReadFile = Nothing
                  intErr = Hex(Err.Number)
                        If intErr <> 0 Then
                              readtextfile = Err.Description
                        Else
                              readtextfile = "0"
                        End If
On Error GoTo 0                        
End Function



if you have any problems let me know.


zf
0
 
zoofanCommented:
Oh it will save the csv file as time_date.csv in the scripts directory and the script will prompt you when its finished( it takes a long time) DO not open the file until you have been prompted that the script is done or you may cause issues with it trying to write to the file.

zf
0
 
bsharathAuthor Commented:
Thanks a lot zoofan.
If you can find if there is a cd in the drive i can raise a new Q....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
zoofanCommented:
before you post it let me test it but 95% sure of a yes,  brb

zf
0
 
bsharathAuthor Commented:
Ok zoofan...
0
 
zoofanCommented:
Yes I can, post it


zf
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now