读取注册表方法(win API C)

 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内做

     }

    }

 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值