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
Printable View
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
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
This could be one of the ways
Edit**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
Thanks alot.
but System.IO.DriveInfo is not defined. Are you sure this codes are for VB.net 2003?
Farhad
well I am not! I use VB.2005. I guse you got to fallow Jumpercables suggestion.
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
Hi,Quote:
Originally Posted by farhad_tmmt
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