USB字母和名称 [英] USB Letter and Name

查看:91
本文介绍了USB字母和名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从插入的磁盘(USB,PCMCIA等)中获取便携式驱动器信息.使用Win32_LogicalDisk,我可以获得文件系统和大小信息,但是不确定如何设置查询以获取与驱动器名称相关的Win32_DiskDrive信息吗?
关于如何找到此信息的任何想法?

有一点问题. USB是SanDisk Cruzer,资源管理器列出了USB的2个驱动器.在硬件选项卡下的属性对话框下列出了我想要的名称.这两个答案都在驱动器上返回空字符串.

感谢您的帮助.
圣诞快乐.

I need to get portable drive information from an inserted disk.(USB,PCMCIA,etc..). Using Win32_LogicalDisk I can get the File System and size information, but am not sure how to set up a query to get the associated Win32_DiskDrive information for the Drive name?
Any ideas on how I can find this information?

Have a little issue. The USB is a SanDisk Cruzer, explorer lists 2 drives for the USB. The Name that I want is listed under the properties dialog under the hardware tab. Both answers are returning empty strings on the drive.

Thanks for the help.
Merry Christmas.

推荐答案

为什么不使用.NET的DriveInfo类.它允许您通过静态方法GetDrives()枚举系统中的所有驱动器.然后,您遍历集合并检查DriveType属性中是否存在USB记忆棒,该属性将为DriveType.Removable.

修改:
DriveInfo类中有一个称为VolumeLabel的属性.那应该是卷标.如果那当然是你的意思.

干杯,

曼弗雷德(Manfred)
Why don''t you use the DriveInfo class of .NET. It lets you enumerate all drives in the system via the static method GetDrives(). Then you iterate over the collection and inspect the DriveType property for USB sticks it would be DriveType.Removable.

Modification:
There is property called VolumeLabel in the DriveInfo class. That should be volume label. If that''s what you meant of course.

Cheers,

Manfred


自由,

我将使用GetVolumeInformation-调用后lpVolumeNameBuffer包含卷名.

Hi Freedom,

I''d use GetVolumeInformation - the lpVolumeNameBuffer contains the Volumename after calling.

[DllImport("kernel32.dll", EntryPoint = "GetVolumeInformationA")]
public static extern int GetVolumeInformation(string lpRootPathName, StringBuilder lpVolumeNameBuffer, int nVolumeNameSize, out int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags, string lpFileSystemNameBuffer, int nFileSystemNameSize);

[DllImport("kernel32.dll", EntryPoint = "GetDriveTypeA")]
public static extern int GetDriveType(string nDrive);




这样使用




use it like this

public const int iVOLNAME_LENGTH = 256;
StringBuilder sbVolumeName = new StringBuilder(iVOLNAME_LENGTH);
int iSerialNumber = 0;
int iCoponentLength = 0;
string strFileSysName = String.Empty;
int iFileSysFlags = 0;

int iResult = CWin32.GetVolumeInformation(driveinfo.Drive, sbVolumeName, iVOLNAME_LENGTH, out iSerialNumber, iCoponentLength, iFileSysFlags, strFileSysName, iVOLNAME_LENGTH);


这篇关于USB字母和名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆