|
-
Nov 8th, 2006, 05:23 PM
#1
Thread Starter
Junior Member
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
-
Nov 8th, 2006, 05:35 PM
#2
Fanatic Member
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
-
Nov 8th, 2006, 05:56 PM
#3
Re: Help: Finding Cd-Rom Drive
This could be one of the ways
VB Code:
For Each dInfo As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()
If dInfo.DriveType = System.IO.DriveType.CDRom Then
MessageBox.Show(dInfo.Name & " is a " & IO.DriveType.CDRom.ToString)
End If
Next
Edit**
Last edited by VBDT; Nov 8th, 2006 at 06:16 PM.
-
Nov 8th, 2006, 06:52 PM
#4
Thread Starter
Junior Member
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
-
Nov 8th, 2006, 07:01 PM
#5
Re: Help: Finding Cd-Rom Drive
well I am not! I use VB.2005. I guse you got to fallow Jumpercables suggestion.
-
Nov 9th, 2006, 08:07 AM
#6
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:
Dim mcls As System.Management.ManagementClass = New System.Management.ManagementClass("Win32_LogicalDisk")
Dim mobcol As System.Management.ManagementObjectCollection = mcls.GetInstances()
For Each mob As System.Management.ManagementObject In mobcol
If Convert.ToInt32(mob("DriveType")) = 5 Then
Dim tmpStr As String
tmpStr = "CDROM Device: " & mob("Name") & ControlChars.NewLine & "Name of CD inserted: "
If mob("Volumename") = "" Then
tmpStr = tmpStr & "NONE"
Else
tmpStr = tmpStr & mob("VolumeName")
End If
MsgBox(tmpStr)
End If
Next
-
Nov 9th, 2006, 11:09 AM
#7
Re: Help: Finding Cd-Rom Drive
 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:
'Use WMI to find all the CDRom Drives and store a few properties.
'We need the Path to get a handle on the drive (we acually use the "//./" & path
Private Sub GetDrives()
Dim cdRomClass As ManagementClass = New ManagementClass("Win32_CDROMDrive")
Dim cdRomDrives As ManagementObjectCollection = cdRomClass.GetInstances
Dim cdromDrivesEnumerator As ManagementObjectCollection.ManagementObjectEnumerator = _
cdRomDrives.GetEnumerator
_drives = New ArrayList
While cdromDrivesEnumerator.MoveNext
Dim thisCDRom As CDROM
Dim cdRomDrive As ManagementObject = _
CType(cdromDrivesEnumerator.Current, ManagementObject)
thisCDRom.Caption = CType(cdRomDrive("Caption"), String)
thisCDRom.Path = CType(cdRomDrive("Drive"), String)
thisCDRom.DevicePath = "//./" & thisCDRom.Path
_drives.Add(thisCDRom)
End While
Hope it helps,
sparrow1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|