Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find all Cdd and DVD with the detail if there is a cd inside the drive.

ASKER CERTIFIED SOLUTION
Avatar of zoofan
zoofan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bsharath

ASKER

Thanks....
How about a free bonus??  lol

Realize this will get messy if you run accross alot of pc's with multi drives, but in single drive machines you may like this better, returns to the file as before, added drive letter assigned and volume label if disc is in.
Output:

PCNAME,DriveLetter,VolumeLabel,DiscIn,DriveModel


'===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
' ''''https://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,DriveLtr,Label,DiscIn,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
Dim discin
Dim strVolume
Dim strDrvLetter

                        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
                        strDrvLetter = strDrvLetter & obj.Drive
                        strVolume = strVolume & "," & obj.VolumeName
                        discin = discin & "," & obj.MediaLoaded
                        getcdrom = getcdrom & "," & getcd
                        Next
                        getcdrom = strDrvLetter & "," & strVolume & "," & discin & "," & getcdrom
                        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



:-)

zf
If you dont need it just use the other, thought you may like a touch more for good measure.

enjoy!

zf
If you have any other hardware queries let me know those i enjoy doing!! :-)

zf
Wow this is a nice one zoofan.An additional benifit for me....:)
Thought you might enjoy the suprise, glad you like.


cheers

zf
I have a Q from a long time.I think you can help...

Is it possible to find all the HDD in a rack server.In what raid are they configured,How many slots they have and how many are free.
esults like.

machinename     No of HDD    HDD size    Raide type     Free slots    

If you can help i can raise a Q....
THX
Sharath
hmmm.....

I think I can get you some of it.  Num of drives yes, size of drive yes, raid type not very confident, and free slots I assume you mean on the controller and that as well not very confident.

These last two in a hardware raid configuration windows would'nt have access to the information as all it see's is one single drive(the array, Which btw would list in No of HDD and size as a single drive) it would know the controller type and thats it as far I know the other information would have to be queried directly from the controller and would be card specific as well as manufacturer specific dont think thats happening or atleast not with my ability.  

I can do Num drives, and drive size with no problem,  which wil include the raid drive(as windows see's it)


zf

For example when you go into disk managment you should see the hardware raid as a single Drive entity within windows,  aside from low-level machine programming specific to the card model and manufacturer thats all your going to get from it I belive.  

My suggestion to start you in a better direction is who makes your raid controller? and what model is it? I will help you look and see if they have any windows based managment/montoring tools.

zf
Ok Zoofan

I only have HP and dell machines...
Zoofan.

This is a relevent Q for the previous post printer status page.The same way but to connect through Mstsc.

https://www.experts-exchange.com/questions/22749002/Need-a-customized-mstsc-console.html