如何确定USB闪存驱动器制造商? [英] how to determine USB Flash drive manufacturer?
问题描述
我要我的程序只能使用特定的USB闪存驱动器(从单一的制造商)工作,而忽略其他所有的USB闪存驱动器(从任何其他制造商)。
I need my program to work only with certain USB Flash drives (from a single manufacturer) and ignore all other USB Flash drives (from any other manufacturers).
是可以检查特定的USB卡插入使用.NET 2.0的窗口?怎么样?
is it possible to check that specific USB card is inserted on windows using .NET 2.0? how?
如果我觉得通过WMI,可我不知怎么确定哪些驱动器号的USB驱动器上?
if I find it through WMI, can I somehow determine which drive letter the USB drive is on?
推荐答案
编辑:加code打印驱动器盘符
Added code to print drive letter.
检查这个例子为你的作品。它使用WMI。
Check if this example works for you. It uses WMI.
Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
...
Console.WriteLine(" Name: {0}", c["Name"]); // here it will print drive letter
满code样品:</ P>
The full code sample:
namespace WMISample
{
using System;
using System.Management;
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
Console.WriteLine("Model: {0}", queryObj["Model"]);
foreach (ManagementObject b in queryObj.GetRelated("Win32_DiskPartition"))
{
Console.WriteLine(" Name: {0}", b["Name"]);
foreach (ManagementBaseObject c in b.GetRelated("Win32_LogicalDisk"))
{
Console.WriteLine(" Name: {0}", c["Name"]); // here it will print drive letter
}
}
// ...
Console.WriteLine("--------------------------------------------");
}
}
catch (ManagementException e)
{
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
}
}
我觉得这些属性可以帮助你从别人区别真正的USB驱动器。与几个随身碟测试以检查值相同。请参阅完整的参考 Win32_DiskDrive 这里的属性:
http://msdn.microsoft.com/ EN-US /库/ aa394132(VS.85)的.aspx
检查,如果这篇文章也是有帮助到您:
Check if this article is also of any help to you:
<一个href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/48a9758c-d4db-4144-bad1-e87f2e9fc979" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/48a9758c-d4db-4144-bad1-e87f2e9fc979
这篇关于如何确定USB闪存驱动器制造商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!