Getting Disk Drives
-
I`m using System.IO.DriveInfo.GetDrives() funcd tion to get DriveInfo anextract information about drives but it works really bad with SATA disks (gives me errors)? Does anybody have solution for this?
Vertyg0 wrote:
but it works really bad with SATA disks (gives me errors)
What are the errors you get exactly? Also a code snippet would be very helpful.
Regards:rose:
-
Vertyg0 wrote:
but it works really bad with SATA disks (gives me errors)
What are the errors you get exactly? Also a code snippet would be very helpful.
Regards:rose:
DriveInfo[] drivesInfo = DriveInfo.GetDrives(); foreach (DriveInfo drive in drivesInfo) listBox1.Items.Add(drive.Name + " " + drive.VolumeLabel); ************** Exception Text ************** System.IO.IOException: The device is not ready. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode) at System.IO.DriveInfo.get_VolumeLabel() at SqlServerMonitor.AddDisk.AddDisk_Load(Object sender, EventArgs e) in C:\...\AddDisk.cs:line 23 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
-
DriveInfo[] drivesInfo = DriveInfo.GetDrives(); foreach (DriveInfo drive in drivesInfo) listBox1.Items.Add(drive.Name + " " + drive.VolumeLabel); ************** Exception Text ************** System.IO.IOException: The device is not ready. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode) at System.IO.DriveInfo.get_VolumeLabel() at SqlServerMonitor.AddDisk.AddDisk_Load(Object sender, EventArgs e) in C:\...\AddDisk.cs:line 23 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
I would put the listBox1.Items.Add... in a try/catch , because you probably are asking your DVD-drive to tell you the VolumeLabel and if there is no DVD in it you will get an exception.
-------------------- Bertram Weckmann www.svizzer.com --------------------