Results 1 to 7 of 7

Thread: Help: Finding Cd-Rom Drive

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    26

    Help: Finding Cd-Rom Drive

    Hello Every One,

    I have a question. How I can find all of the Cd Disk Dirve of destination pc in vb.net2003? I'm trying to access the cd becuase want to execute just if the cd is in the Cd-Rom Drive. Ok?

    Please, Help me if you can.

    Thanks,
    Farhad
    VB 2003

  2. #2
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Help: Finding Cd-Rom Drive

    I believe you are going to have to use the System.Management Namespace. Which according to MSDN provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Applications and services can query for interesting management information (such as how much free space is left on the disk, what is the current CPU utilization, which database a certain application is connected to, and much more), using classes derived from ManagementObjectSearcher and ManagementQuery, or subscribe to a variety of management events using the ManagementEventWatcher class. The accessible data can be from both managed and unmanaged components in the distributed environment.

    http://msdn2.microsoft.com/en-us/lib...t_members.aspx

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  3. #3
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Help: Finding Cd-Rom Drive

    This could be one of the ways
    VB Code:
    1. For Each dInfo As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()
    2.             If dInfo.DriveType = System.IO.DriveType.CDRom Then
    3.                 MessageBox.Show(dInfo.Name & " is a " & IO.DriveType.CDRom.ToString)
    4.             End If
    5.         Next
    Edit**

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    26

    Re: Help: Finding Cd-Rom Drive

    Thanks alot.

    but System.IO.DriveInfo is not defined. Are you sure this codes are for VB.net 2003?

    Farhad
    VB 2003

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Help: Finding Cd-Rom Drive

    well I am not! I use VB.2005. I guse you got to fallow Jumpercables suggestion.

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Help: Finding Cd-Rom Drive

    DriveInfo is not present under VS 2003.

    You would have to use WMI scripting, or Management Class objects for this.
    VB Code:
    1. Dim mcls As System.Management.ManagementClass = New System.Management.ManagementClass("Win32_LogicalDisk")
    2.         Dim mobcol As System.Management.ManagementObjectCollection = mcls.GetInstances()
    3.         For Each mob As System.Management.ManagementObject In mobcol
    4.             If Convert.ToInt32(mob("DriveType")) = 5 Then
    5.                 Dim tmpStr As String
    6.                 tmpStr = "CDROM Device: " & mob("Name") & ControlChars.NewLine & "Name of CD inserted: "
    7.                 If mob("Volumename") = "" Then
    8.                     tmpStr = tmpStr & "NONE"
    9.                 Else
    10.                     tmpStr = tmpStr & mob("VolumeName")
    11.                 End If
    12.                 MsgBox(tmpStr)
    13.             End If
    14.         Next
    Show Appreciation. Rate Posts.

  7. #7
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Help: Finding Cd-Rom Drive

    Quote Originally Posted by farhad_tmmt
    Thanks alot.

    but System.IO.DriveInfo is not defined. Are you sure this codes are for VB.net 2003?

    Farhad
    Hi,

    You could try this in VB.net 2003;

    VB Code:
    1. 'Use WMI to find all the CDRom Drives and store a few properties.
    2.     'We need the Path to get a handle on the drive (we acually use the "//./" & path
    3.     Private Sub GetDrives()
    4.         Dim cdRomClass As ManagementClass = New ManagementClass("Win32_CDROMDrive")
    5.         Dim cdRomDrives As ManagementObjectCollection = cdRomClass.GetInstances
    6.         Dim cdromDrivesEnumerator As ManagementObjectCollection.ManagementObjectEnumerator = _
    7.             cdRomDrives.GetEnumerator
    8.         _drives = New ArrayList
    9.         While cdromDrivesEnumerator.MoveNext
    10.             Dim thisCDRom As CDROM
    11.             Dim cdRomDrive As ManagementObject = _
    12.                CType(cdromDrivesEnumerator.Current, ManagementObject)
    13.             thisCDRom.Caption = CType(cdRomDrive("Caption"), String)
    14.             thisCDRom.Path = CType(cdRomDrive("Drive"), String)
    15.             thisCDRom.DevicePath = "//./" & thisCDRom.Path
    16.             _drives.Add(thisCDRom)
    17.         End While

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width