标签: removable

C#如何知道可移动磁盘是USB驱动器还是SD卡?

Windows 7平台,C#

我使用以下语句列出所有驱动器:

DriveInfo[] drives = DriveInfo.GetDrives();
Run Code Online (Sandbox Code Playgroud)

然后我可以使用DriveType找出所有可移动磁盘:

foreach (var drive in drives)
{
     if(drive.DriveType == DriveType.Removable)
         yield return drive;
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题是,SD卡磁盘和USB闪存盘共享相同的driveType:可移动,那么我怎么才能找到USB闪存盘?

谢谢!

c# removable

15
推荐指数
1
解决办法
2661
查看次数

在c#中获取可移动媒体驱动器列表

嗨我需要在c#中检测所有可移动媒体驱动器ia下拉菜单

任何帮助将不胜感激

谢谢

c# detect removable

8
推荐指数
1
解决办法
9042
查看次数

始终检测可移动设备的最佳方法

在我之前的问题"如何找到闪存设备的唯一序列号?" 我最终要求找到驱动器号的方法.那个问题解决了.

但是,我的初步问题尚未得到解答.我希望能够将可移动设备(USB驱动器,SD卡,(外部硬盘驱动器?)等)分开,并且在重新连接时始终能够再次识别它们.这也应该可以在任何其他计算机上使用.幸运的是,我不关心正在格式化的驱动器(如果/何时,它们在我的程序中被视为新驱动器),那么我可以使用分区和卷ID作为我识别的一部分吗?我问这是因为PNPDeviceID 不是唯一的.我发现它取决于阅读它的硬件,见下图:

替代文字http://i48.tinypic.com/28uofmc.png

替代文字http://i46.tinypic.com/rk5tv6.jpg

因此,我正在搜索的是一种使用以下方法检测和识别任何计算机上的任何可移动设备的方法:Win32_DiskDrive,Win32_DiskPartition,Win32_LogicalDisk.我要感谢RRUZ的原始代码:

program GetWMI_USBConnectedInfo;

{$APPTYPE CONSOLE}

uses
  Windows,
  Classes,
  ActiveX,
  Variants,
  SysUtils,
  WbemScripting_TLB in '..\..\Documents\RAD Studio\5.0\Imports\WbemScripting_TLB.pas';

procedure  GetUSBDiskDriveInfo;
var
  WMIServices  : ISWbemServices;
  Root,a,b     : ISWbemObjectSet;
  Item,Item2   : Variant;
  i,ii,iii,iiii: Integer;
  start,stop,freq:Int64;
begin
  QueryPerformanceFrequency(freq);
  QueryPerformanceCounter(start);

  WMIServices := CoSWbemLocator.Create.ConnectServer('.', 'root\cimv2','', '', '', '', 0, nil);
  Root := WMIServices.ExecQuery('Select * From Win32_DiskDrive','WQL', 0, nil);
  for i := 0 to Root.Count - 1 do
  begin
    Item := Root.ItemIndex(i);
    for ii …
Run Code Online (Sandbox Code Playgroud)

delphi wmi removable-drive delphi-2007 removable

6
推荐指数
1
解决办法
4886
查看次数

标签 统计

removable ×3

c# ×2

delphi ×1

delphi-2007 ×1

detect ×1

removable-drive ×1

wmi ×1