removable-drive

How to get the list of removable disk in c#?

﹥>﹥吖頭↗ 提交于 2019-11-30 17:14:36
I want to get the list of removable disk in c#. I want to skip the local drives. Because i want the user to save the file only in removable disk. Lloyd Powell You will need to reference System.IO for this method. var driveList = DriveInfo.GetDrives(); foreach (DriveInfo drive in driveList) { if (drive .DriveType == DriveType.Removable) { //Add to RemovableDrive list or whatever activity you want } } Or for the LINQ fans: var driveList = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Removable); Added As for the Saving part, as far as I know I don't think you can restrict where the

How to eject a USB removable disk/volume, similar to the “Eject” function in Windows Explorer?

别来无恙 提交于 2019-11-30 11:42:52
Do you know what is the API, or sequence of API calls that windows uses to accomplish the "Eject" function which is available on the shell context menu for removable volumes? So far I've tried two things: using CM_Request_Device_Eject , I enumerate the removable disks (using the SetupDiXXX APIs ), find the one that I'm interested in, walk the device manager hierarchy (using CM_XXX APIs ) and finally call CM_Request_Device_Eject on the devInst of the device I'm interesed in. This works in the sense that it does remove the volumes from My Computer and makes the device "safe to remove" (ready to

How to get the list of removable disk in c#?

孤街浪徒 提交于 2019-11-30 01:22:07
问题 I want to get the list of removable disk in c#. I want to skip the local drives. Because i want the user to save the file only in removable disk. 回答1: You will need to reference System.IO for this method. var driveList = DriveInfo.GetDrives(); foreach (DriveInfo drive in driveList) { if (drive .DriveType == DriveType.Removable) { //Add to RemovableDrive list or whatever activity you want } } Or for the LINQ fans: var driveList = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType

How to eject a USB removable disk/volume, similar to the “Eject” function in Windows Explorer?

老子叫甜甜 提交于 2019-11-29 17:31:46
问题 Do you know what is the API, or sequence of API calls that windows uses to accomplish the "Eject" function which is available on the shell context menu for removable volumes? So far I've tried two things: using CM_Request_Device_Eject, I enumerate the removable disks (using the SetupDiXXX APIs), find the one that I'm interested in, walk the device manager hierarchy (using CM_XXX APIs) and finally call CM_Request_Device_Eject on the devInst of the device I'm interesed in. This works in the

Detect insertion of media into a drive using windows messages

荒凉一梦 提交于 2019-11-29 00:12:24
I am currently using WM_DEVICECHANGE to be notified when new USB drives are connected to the computer. This works great for devices like thumb-drives where as soon as the device arrives it is ready to have files read from it. For devices like SD card readers it does not because the message is sent out once when the device is connected but no message is sent when a user actually inserts a card into the device. Is it possible to detect the insertion of new media into an existing USB device without having to use polling? I just did this a few weeks ago. Technically speaking the

GetDriveType in C#? or find out if my drive is removable?

纵然是瞬间 提交于 2019-11-28 13:48:56
I am using Environment.GetLogicalDrives(); to get a list of drives. I remember in c++ i could use GetDriveType to find if the device was CD, removable, flash, etc and i am thinking i want to put a filter in my app to only show CD and removable on default. What is the GetDriveType equivalent in C#? google only showed me hacks to use the c++ call. Yes, the framework includes a DriveType enumeration used by the DriveInfo class. Have a look at the GetDrives() method on MSDN. DriveInfo is the class you are looking for. 来源: https://stackoverflow.com/questions/623254/getdrivetype-in-c-or-find-out-if

Get notification when a new drive is connected via USB or other means (C#)

不打扰是莪最后的温柔 提交于 2019-11-28 07:34:31
问题 I need to detect when a new drive is plugged into a Windows system through a USB port, firewire port, etc. I am aware of the WM_DEVICECHANGE message, but this requires a window to be open in order to use it. Is there a way to create a background process in C# that detects when new drives are plugged in? Background info: I am wanting to write this app to remove a worm from company removable drives. Regular antivirus software is failing to removing it. We have a script that will remove the worm

How to find the unique serial number of a flash device?

安稳与你 提交于 2019-11-27 15:22:51
问题 I've found several snippets and .pas files that can detect when USB flash drives are inserted and removed. Some give all kind of good information, however what I need is the devices' unique serial number, not the volumes' serial number. My current .pas file (which I don't remember where I found) also seems to detect SD cards (which I like). If you want a look, you can find it here (it only returns the drive number and inserted/removed): unit UsbDetector; interface uses Classes; type

Detect insertion of media into a drive using windows messages

こ雲淡風輕ζ 提交于 2019-11-27 15:17:40
问题 I am currently using WM_DEVICECHANGE to be notified when new USB drives are connected to the computer. This works great for devices like thumb-drives where as soon as the device arrives it is ready to have files read from it. For devices like SD card readers it does not because the message is sent out once when the device is connected but no message is sent when a user actually inserts a card into the device. Is it possible to detect the insertion of new media into an existing USB device