private static void loadUSB() { _loading = true; //lstInfo.Items.Clear(); // display volumes VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); try { foreach (Volume device in volumeDeviceClass.Devices) { if (device.IsUsb) { // lstInfo.Items.Add(device.Description + " " + device.LogicalDrive + "" + device.FriendlyName); Console.WriteLine("Find the device:" + device.Description + " " + device.LogicalDrive + "" + device.FriendlyName); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } _loading = false; }
public bool Eject() { if (!extracted) { return(false); } VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume dev in volumeDeviceClass.Devices) { try { if (dev.LogicalDrive.Equals(this.Letter + ":")) { dev.Eject(true); volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume temp in volumeDeviceClass) { if (temp.LogicalDrive.Equals(this.Letter + ":")) { return(false); } } return(true); } } catch { break; } } return(false); }
public bool Eject() { if (!extracted) { return(false); } VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume dev in volumeDeviceClass.Devices) { try { if (dev.LogicalDrive.Equals(this.tomeName + ":")) { dev.Eject(true); volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume temp in volumeDeviceClass) { if (temp.LogicalDrive.Equals(this.tomeName + ":")) { return(false); } } return(true); } } catch { System.Console.WriteLine("Error"); break; } } return(false); }
public bool Eject() { var ejectDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == this.Name.Remove(2)); ejectDevice.Eject(false); ejectDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == this.Name.Remove(2)); return(ejectDevice == null); }
public bool EjectDevice(Device device) { var dev = new VolumeDeviceClass().SingleOrDefault(p => p.LogicalDrive == device.Volumes.First().Name); dev?.Eject(false); var volume = new VolumeDeviceClass(); return(volume.Where(x => !string.IsNullOrEmpty(x.LogicalDrive)).Any(p => p.LogicalDrive.Equals(dev.LogicalDrive))); }
public bool IsFree() { VolumeDeviceClass elem = new VolumeDeviceClass(); var v = new VolumeDeviceClass().SingleOrDefault(volume => volumes.FindIndex(vol => vol.Name == volume.LogicalDrive) > -1); v.Eject(false); return(new VolumeDeviceClass().SingleOrDefault(volume => volumes.FindIndex(vol => vol.Name == volume.LogicalDrive) > -1) == null); }
public bool Eject() { var tempName = this.DeviceFriendlyName.Remove(2); var ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == tempName); ejectedDevice.Eject(false); var tempDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == tempName); if (tempDevice == null) { return(true); } return(false); }
public bool EjectDevice() { var tempName = this.DeviceName.Remove(2); var ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == this.DeviceName.Remove(2)); if (!IsMtpDevice) { ejectedDevice.Eject(false); ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == tempName); } else { return(false); } return(ejectedDevice == null); }
public bool EjectDevice() { var tempName = this.DeviceName.Remove(2); //получаем том девавйса var ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == tempName); //получаем значение состояния девайса if (!IsMtpDevice) { ejectedDevice.Eject(false); ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == tempName);//повторное подключение к девайсу после поытки извлечения } else { return(false); } return(ejectedDevice == null); }
void CheatU9Telit() { // U9 telit appears as USB CDrom on the bus, until disk eject is sent. // Then, it reappears as normal stuff. VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume device in volumeDeviceClass.Devices) { if (device.FriendlyName == "PCL HSUPA Modem USB Device") { NihLog.Write(NihLog.Level.Info, "Trying to initialize: " + device.FriendlyName); device.EjectCDRomNoUI(); } } }
/// <summary> /// Метод извлечения устройства ( RemoveDrive ) /// </summary> /// <returns>true - извлечено; false - не извлечено</returns> public bool EjectDevice() { var ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == this.DeviceName.Remove(2)); ejectedDevice.Eject(true); ejectedDevice = new VolumeDeviceClass().SingleOrDefault(v => v.LogicalDrive == this.DeviceName.Remove(2)); if (ejectedDevice == null) { return(true); } else { return(false); } }
private bool AttemptUsbEject() { try { using (var x = new VolumeDeviceClass()) { var device = x.Devices.FirstOrDefault(d => { Volume v = d as Volume; if (v == null || v.LogicalDrive == null) { return(false); } return(_destinationDeviceRoot.StartsWith(v.LogicalDrive)); }); string ejectionResult = "---"; if (device != null) { Thread.Sleep(1000); //wait for our actions to die down ejectionResult = device.Eject(false); } if (ejectionResult != null) { Thread.Sleep(2000); //wait for our actions to die down ejectionResult = device.Eject(false); if (ejectionResult != null) { SystemSounds.Asterisk.Play(); _safeToRemoveLabel.Text = ejectionResult; } } _safeToRemoveLabel.Visible = true; return(ejectionResult == null); } } catch (Exception err) { SIL.Reporting.ErrorReport.NotifyUserOfProblem(err, "Could not eject the usb memory stick."); return(false); } }
/// <summary> /// Отключаем заданный usb (пытаемся 9 раз с перерывом в 333 мс) /// </summary> private void DetachUsb(string driveLetter) { var volumes = new VolumeDeviceClass(); foreach (Volume vol in volumes.Devices) { if (vol.LogicalDrive == driveLetter) { for (int i = 0; i < 9; ++i) { try { vol.Eject(false); return; } catch (Win32Exception) { Thread.Sleep(333); continue; } } } } }
private void buttonDisagree_Click(object sender, EventArgs e) { logger.Info("<I Disagree> clicked"); this.Hide(); var setting = ConfigurationManager.AppSettings["EjectOnDisagree"]; if (!String.IsNullOrEmpty(setting) && Convert.ToBoolean(setting) == true) { var drive = Drive.TrimEnd('\\'); VolumeDeviceClass volumes = new VolumeDeviceClass(); foreach (Volume vol in volumes.Devices) { if (vol.LogicalDrive.Equals(drive)) { logger.Info("Attempting to eject drive: " + Drive); vol.Eject(false); logger.Info("Done ejecting drive."); break; } } } }
private static void ejectUSB() { _loading = true; VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume device in volumeDeviceClass.Devices) { if (device.IsUsb) { //lstInfo.Items.Add(device.Description + " " + device.LogicalDrive + "" + device.FriendlyName); string s = device.Eject(true); if (s != null) { Console.WriteLine("Error:" + s); } else { Console.WriteLine("Eject USB:" + device.Description + " " + device.LogicalDrive + "" + device.FriendlyName); } } } _loading = false; }
public int Eject(string LogicalDisk) { //MessageBox.Show("ejected"); VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); foreach (Volume device in volumeDeviceClass.Devices) { // is this volume on USB disks? if (!device.IsUsb) continue; //MessageBox.Show("ejected"); // is this volume a logical disk? if ((device.LogicalDrive == null) || (device.LogicalDrive.Length == 0)) continue; if (device.LogicalDrive.ToString() + "\\" == LogicalDisk) { //MessageBox.Show("ejected"); //MessageBox.Show( device.Eject(true)); string str = device.Eject(true); //MessageBox.Show(str); System.Console.WriteLine(str); this.DelDiskStatus(LogicalDisk); // allow Windows to display any relevant UI //MessageBox.Show(device.LogicalDrive.ToString()); } else { continue; } } return 0; }
private void UsbInsert() { //_loading = true; //treeViewDisks.Nodes.Clear(); //TreeNode root = treeViewDisks.Nodes.Add("Computer"); //root.ImageIndex = (int)IconIndex.MyComputer; //root.SelectedImageIndex = root.ImageIndex; // display volumes VolumeDeviceClass volumeDeviceClass = new VolumeDeviceClass(); //TreeNode volumesNode = new TreeNode("Volumes"); //volumesNode.ImageIndex = (int)IconIndex.Volume; //volumesNode.SelectedImageIndex = volumesNode.ImageIndex; //root.Nodes.Add(volumesNode); foreach (Volume device in volumeDeviceClass.Devices) { if ((!device.IsUsb))// &&(usbOnlyToolStripMenuItem.Checked)) { continue; } //string text = null; //if ((device.LogicalDrive != null) && (device.LogicalDrive.Length > 0)) //{ // text += device.LogicalDrive; //} //if (text != null) //{ // text += " "; //} //text += device.Description; //if (device.FriendlyName != null) //{ // if (text != null) // { // text += " - "; // } // text += device.FriendlyName; //} //TreeNode deviceNode = volumesNode.Nodes.Add(text); //if (device.IsUsb) //{ // deviceNode.ImageIndex = (int)IconIndex.Box; // deviceNode.SelectedImageIndex = deviceNode.ImageIndex; //} //deviceNode.Tag = device; //foreach (Device disk in device.Disks) //{ // TreeNode diskNode = deviceNode.Nodes.Add(disk.Description + " - " + disk.FriendlyName); // diskNode.ImageIndex = deviceNode.ImageIndex; // diskNode.SelectedImageIndex = diskNode.ImageIndex; // diskNode.Tag = device; //} } //root.ExpandAll(); //_loading = false; }