请问windows下判断盘符(driverletters)的问题

hgw111 2002-04-15 09:19:55
我做一个程序时需要判断USB外设的盘符,例如:当一个USB硬盘插到计算机上时,我要能够判断出系统给他分配的是E:,F:还是G:,同时我还要知道它的唯一标示(也就是硬件ID).
我费了不少力气能够做到判断USB的硬件标示,利用下述代码:
HDEVINFO DeviceInfoSet;
DeviceInfoSet=SetupDiGetClassDevs((LPGUID)&GUID_DEVCLASS_DISKDRIVE,
0, 0, DIGCF_PRESENT);
//  Enumerate through all Devices.    
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
char buffer[255];
DWORD buffersize=255;
DWORD DataT;
CString identify;
for(int j=0;SetupDiEnumDeviceInfo(DeviceInfoSet,j,&DeviceInfoData); j++)
{
SetupDiGetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData,
SPDRP_HARDWAREID,&DataT, (PBYTE)buffer,buffersize,&buffersize);
// id string is now in "buffer"
identify=buffer;
if(identify.Find("SigmaTel",0)!=-1)
{
SetupDiGetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData,
SPDRP_DRIVER ,&DataT, (PBYTE)buffer,buffersize,&buffersize);
// SetupDiGetDriverInfoDetail(DeviceInfoSet,DeviceInfoData,&DriverInfoDetailData,&DriverInfoDetailData
identify=buffer;
DeviceInfoData.ClassGuid;
DeviceInfoData.DevInst;
MessageBox(identify);
}
}
可上述代码没办法做到一个盘符一个盘符的判断,只能一整块硬盘,一整个USB的判断,我让他取盘符,他返回给我一串字符:
{4D36E967-E325-11CE-BFC1-08002BE10318}\0001

{4D36E967-E325-11CE-BFC1-08002BE10318}是USB的标示,0001应该是盘符(在不同的机器上不一样,而且在注册表中有相关内容)
那么请问:我如何才能将0001专为盘符?或是我如何才能做到判断盘符和usb的硬件ID?
...全文
317 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
hgw111 2002-05-16
  • 打赏
  • 举报
回复
masterz():
I sovled this problem with register.Please look the key following:
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum
it stores the infomation of the hardware by primary keys.For example,I have a usb hardware named myhd,the keyvalue of HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\myhd is the hardware infomation includs hardwareID.
In win98,winme(I have not test in win95),there is a subkey----CurrentDriveLetterAssignment if the hardware have driver letter,it has the current driver letter.Then I must prove the hardware is in use.see the key----HKEY_DYN_DATA\\Config Manager\\Enum
In win2000(I have not test in NT),the key CurrentDriveLetterAssignment can not be finded,there is another key named HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices,it stores the driver letter,I finded the relation between HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\myhd and HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices by the key following:
SYSTEM\\CurrentControlSet\\Control\\DeviceClasses";
masterz():
I sovled this problem with register.Please look the key following:
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum
it stores the infomation of the hardware by primary keys.For example,I have a usb hardware named myhd,the keyvalue of HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\myhd is the hardware infomation includs hardwareID.
In win98,winme(I have not test in win95),there is a subkey----CurrentDriveLetterAssignment if the hardware have driver letter,it has the current driver letter.Then I must prove the hardware is in use.see the key----HKEY_DYN_DATA\\Config Manager\\Enum
In win2000(I have not test in NT),the key CurrentDriveLetterAssignment can not be finded,there is another key named HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices,it stores the driver letter,I finded the relation between HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\myhd and HKEY_LOCAL_MACHINE\\SYSTEM\\MountedDevices by the key following:
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\DeviceClasses";
HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum

Please research the details by yourself.
hgw111 2002-05-16
  • 打赏
  • 举报
回复
这个问题我自己解决了,经研究microsoft的MFC和SDK没有提供类似的函数或编程接口,解决类似的问题有两种办法:1.利用2000,98或me的DDK写驱动程序; 2 查询注册表,在注册表中(不管2000,98或me)有一条线连着所有的类似信息,可以动态的查询出来。
多谢各位帮忙。
FlyingSch 2002-05-06
  • 打赏
  • 举报
回复
DWORD GetLogicalDrives()
position 1 is drive B, bit position 2 is drive C, and so on.
GetDriveType()
hgw111 2002-05-06
  • 打赏
  • 举报
回复
yu_hl(卖柴火的小男孩):
thank you
Win98 does not support UNICODE,I should use char.But please tell me how can I get the driver letter of USB Device.
yu_hl 2002-05-06
  • 打赏
  • 举报
回复
win98 does not support UNICODE.

TCHAR is the same as char in win98.
halcyon 2002-05-06
  • 打赏
  • 举报
回复
very interesting
icelight 2002-05-04
  • 打赏
  • 举报
回复
TCHAR dosdevname[1026];

does win98 support UNICODE?
yu_hl 2002-05-04
  • 打赏
  • 举报
回复
GetDriverName is only for Windows CE.
Colorstone0823 2002-05-04
  • 打赏
  • 举报
回复
关注
hgw111 2002-05-04
  • 打赏
  • 举报
回复
masterz():
But I can not find the function---GetDriverName in MSDN !Is it a API or MFC function?
masterz 2002-05-01
  • 打赏
  • 举报
回复
This function prompts a user for the driver name of a newly inserted PC card, including USB cards. This function is called to get the driver name for a PCMCIA device if the system cannot determine a driver name based on the Plug and Play ID.

BOOL GetDriverName (
HWND hParent,
PGETDRIVERNAMEPARMS pDriverParms);
hgw111 2002-04-17
  • 打赏
  • 举报
回复
masterz():
I have a USB brand is NEO,and another USB brand is SONY,which one is the USB of SONY if I use them at the same time?
another question,is the return string of QueryDosDevice always
same in different computers or different version of windows?There is a error return value when I do this in win98,although it is successful in win2000 and the MSDN told me QueryDosDevice can be used in both win98 and win2000,the codes like following:
TCHAR dosdevname[1026];
::QueryDosDevice( "C: ",dosdevname,1027);
MessageBox(dosdevname); //in win 98 dosdevname return "烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫 ",my win98 is the second edition of chinese
thank you very much!
hgw111 2002-04-17
  • 打赏
  • 举报
回复
masterz():
I have a USB brand is NEO,and another USB brand is SONY,which one is ten USB of SONY if I use them at the same time?
another question,is the return string of QueryDosDevice always
same in different computers of different version of windows?There is a error return value when I do this in win98,although it is successful in win2000 and the MSDN told me QueryDosDevice can be used in both win98 and win2000,the codes like following:
TCHAR dosdevname[1026];
::QueryDosDevice("C:",dosdevname,1027);
MessageBox(dosdevname); //in win 98 dosdevname return "烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫",my win98 is the second edition of chinese
thank you very much!
masterz 2002-04-15
  • 打赏
  • 举报
回复
you can try GetDriveType GetDriverInfo
masterz 2002-04-15
  • 打赏
  • 举报
回复
I think QueryDosDevice would return different string for different device.
hgw111 2002-04-15
  • 打赏
  • 举报
回复
masterz():
But which is the one I really want to check ,if I have two USB devices?
masterz 2002-04-15
  • 打赏
  • 举报
回复
for my USB removable hard disk, output is like the following
DRIVE_REMOVABLE
\Device\Harddisk1\DP<1>0-0+9
#include "stdafx.h"
#include "windows.h"
int main(int argc, char* argv[])
{
TCHAR drivename[]=_T("I:");
UINT utype=GetDriveType(drivename);
switch(utype)
{
case DRIVE_UNKNOWN:
printf("DRIVE_UNKNOWN \n");
break;
case DRIVE_NO_ROOT_DIR:
printf("DRIVE_NO_ROOT_DIR \n");
break;
case DRIVE_REMOVABLE:
printf("DRIVE_REMOVABLE \n");
break;
case DRIVE_FIXED:
printf("DRIVE_FIXED \n");
break;
case DRIVE_REMOTE:
printf("DRIVE_REMOTE \n");
break;
case DRIVE_CDROM:
printf("DRIVE_CDROM \n");
break;
case DRIVE_RAMDISK:
printf("DRIVE_RAMDISK \n");
break;
default:
printf("error drive type \n");
break;
}
TCHAR dosdevname[1026];
QueryDosDevice(drivename,dosdevname,1024);
printf("%s\n",dosdevname);
}
hgw111 2002-04-15
  • 打赏
  • 举报
回复
masterz():
GetDriveType can not get so much infomation,only followed:
DRIVE_UNKNOWN The drive type cannot be determined.
DRIVE_NO_ROOT_DIR T he root path is invalid. For example, no volume is mounted at the path.
DRIVE_REMOVABLE The disk can be removed from the drive.
DRIVE_FIXED The disk cannot be removed from the drive.
DRIVE_REMOTE The drive is a remote (network) drive.
DRIVE_CDROM The drive is a CD-ROM drive.
DRIVE_RAMDISK The drive is a RAM disk.
there is no GerDriveInfo function,what should I do?

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧