char key_USBname[ SIZEOF_DEVICE_NAME] = {0} ;
char full_name[ SIZEOF_DEVICE_NAME] = {0} ;
char full_USBAllName[ SIZEOF_DEVICE_NAME] = {0} ;
char full_nameSub[ SIZEOF_DEVICE_NAME] = {0} ;
char Key_DevSubname[ SIZEOF_DEVICE_NAME] = {0} ;
HKEY hDevSubKey;
FILETIME file_time;
HKEY hkey ;
HKEY hKeysub;
int index ;
DWORD size ;
index = 0 ;
// 查找USB项下面所有的设备注册名
if( RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SYSTEM//CurrentControlSet//Enum//USB",
0,
KEY_READ,
&hkey) == ERROR_SUCCESS)
{
size = SIZEOF_DEVICE_NAME ;
while( RegEnumKeyExA(hkey,
index,
key_USBname,
&size,
NULL,
NULL,
NULL,
&file_time) == ERROR_SUCCESS)
{
sprintf(full_USBAllName,
"SYSTEM//CurrentControlSet//Enum//USB//%s",
key_USBname) ;
char Key_USBSubname[ SIZEOF_DEVICE_NAME] = {0} ;
int iUSBSubIndex = 0;
//查找设备注册名对应的具体设备
if( RegOpenKeyExA(HKEY_LOCAL_MACHINE,
full_USBAllName,
0,
KEY_READ,
&hKeysub) == ERROR_SUCCESS)
{
FILETIME USBSub_time;
DWORD isize = SIZEOF_DEVICE_NAME ;
while( RegEnumKeyExA(hKeysub,
iUSBSubIndex,
Key_USBSubname,
&isize,
NULL,
NULL,
NULL,
&USBSub_time) == ERROR_SUCCESS)
{
//如还需向下查询继续使用此种方法,也可改写成递归的方式来实现
//结构if打开 while读取
//需要做什么就在while内做
}
}
}