English 中文(简体)
如果没有WMI,通过其他途径检测HDD是否连接了USB
原标题:Detecting if HDD is connected thru USB or by other means without WMI

我想指出,如果联通驱动器连接U、thru SATA、IDE、eSATA或Pewire。 是否有办法不使用WMI? Im利用该法典获取一些信息。

 DriveInfo[] drives = DriveInfo.GetDrives();
 foreach (DriveInfo drive in drives) {
    // DriveType.Fixed && DriveType.Removable

 }

遗憾的是,所有HDD连接的星座的这种回报。 DriveType.Fixed,只有USB 标准为<代码> DriveType.Removable。

我猜想像我这样想......我不知道我实际上所期待的东西。 遗憾的是,<代码>GetVolume Information.n t 提供了了解的途径。 InterfaceType

    [DllImport("kernel32.dll")]
    private static extern long GetVolumeInformation(
        string PathName, 
        StringBuilder VolumeNameBuffer, 
        UInt32 VolumeNameSize, 
        ref UInt32 VolumeSerialNumber, 
        ref UInt32 MaximumComponentLength, 
        ref UInt32 FileSystemFlags, 
        StringBuilder FileSystemNameBuffer, 
        UInt32 FileSystemNameSize);

我要ski。 我确实知道,我可以越来越多地发现这一法典:

  ManagementObjectSearch theSearcher = new ManagementObjectSearcher(
  "SELECT * FROM Win32_DiskDrive WHERE InterfaceType= USB ");

但我倾向于避免。

问题回答

我不敢肯定,为什么你需要如此具体的变化;但你不得不使用海事委员会。 不幸的是,虽然以USB为基地的硬拷贝可以拆除,但它仍然使用实际的磁盘而不是闪光记忆。 因此,<条码>驱动Info将更有可能认为其固定。

The only alternative would be to import the System.Management Assembly.

您可以检索每个驾车的Busfo。 或者可能利用这一工具检索。 说明/代码。 通常用于撰写custom驱动因素

But this may be your best suite; as it includes a way to simply determine if the drive is considered external or not. Which obviously won t address the fixed / removable but will assist in targeting the type of device.

希望能帮助你们。

装置管理员APIC当然能够告诉你,每张磁盘上有哪台公共汽车和控制器。 但是,这并不十分友好。 我建议在C++中写出这一部分,然后与C++/CLI或设计-for-p/invoke出口进行C#-友好接口。

这一解决办法的核心将是<代码>。 SetupDiGetDeviceRegistryProperty to fetch the Value associated with SPDRP_BUSTYPEGUID。 但是,要获得正确的<代码>HDEVINFO和PSP_DEVINFO_DATA处理需要一些工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签