110,538
社区成员
发帖
与我相关
我的任务
分享
string s;
string[] logDrives=new string[10];
logDrives = System.IO.Directory.GetLogicalDrives();//取所有盘符。
for (int i = 0; i < logDrives.Length; i++)
{
if (api.GetDriveType(logDrives[i]) == 2)//判断是不是usb类型
{
s += logDrives[i].ToString();
}
}
api函数调用:
public class api
{
[DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
[DllImport("kernel32.dll", EntryPoint = "GetVolumeInformationA")]
public static extern int GetVolumeInformation(string lpRootPathName, StringBuilder lpVolumeNameBuffer, int nVolumeNameSize, int lpVolumeSerialNumber, int lpMaximumComponentLength, int lpFileSystemFlags, string lpFileSystemNameBuffer, int nFileSystemNameSize);
[DllImport("kernel32.dll", EntryPoint = "GetDriveTypeA")]
public static extern int GetDriveType(string nDrive);
}