TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Software World > Programming

Notices

how to get hardware id using device id?

Programming


Reply
 
Thread Tools Display Modes
Old 12-10-2009, 08:10 PM   #1
Newbie
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0 lathareddy is an unknown quantity at this point


OS: Windows XP


how to get hardware id using device id?

Hi friends,
i am new to vc++.i want to get hardware id of the usb device whenever user connects it to the system using vc++6.0. i got device id using "win32_USBHub" wmi class. is this possible to get hardware id by this device id...

i heard about "setupdigetdeviceregistryproperty"..could any one provide some sample code about this..(plz assume usb is connected to the system)..

please help me on this..i am trying for this from past one week..


Thanks in advance
lathareddy is offline   Reply With Quote
Old 19-10-2009, 12:01 PM   #2
Support Staff
 
Albin's Avatar
 
Join Date: Jan 2008
Posts: 192
Thanks: 1
Thanked 17 Times in 16 Posts
Rep Power: 3 Albin will become famous soon enough


OS: Windows 98 / Windows ME Windows XP Windows Vista


Send a message via Yahoo to Albin
Re: how to get hardware id using device id?

Check these..





Good Luck!!
__________________
_______________
Cheers,
Albin

"We are all either fools or undiscovered geniuses."
Albin is offline   Reply With Quote
Old 19-10-2009, 09:48 PM   #3
Newbie
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0 lathareddy is an unknown quantity at this point


OS: Windows XP


Re: how to get hardware id using device id?

Thanks for reply albin,
anyhow i solved my problem...here i am posting code..it may helpful to others.

Code:
HDEVINFO hDevInfo;
   SP_DEVINFO_DATA DeviceInfoData;
   DWORD i;
 
   // Create a HDEVINFO with all present devices.
   hDevInfo = SetupDiGetClassDevs(NULL,
       0, // Enumerator
       0,
       DIGCF_PRESENT | DIGCF_ALLCLASSES );
 
   if (hDevInfo == INVALID_HANDLE_VALUE)
   {
       //Error handling here.
           printf("Error Details:[%s]\n","INVALID_HANDLE_VALUE");
       return 1;
   }
 
   // Enumerate through all devices in Set.
 
   DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
   for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
       &DeviceInfoData);i++)
   {
       DWORD DataT;
       LPTSTR buffer = NULL;
           LPTSTR hwbuffer=NULL;
       DWORD buffersize = 0;
 
       //
       // Call function with null to begin with, 
       // then use the returned buffer size (doubled)
       // to Alloc the buffer. Keep calling until
       // success or an unknown failure.
       //
       //  Double the returned buffersize to correct
       //  for underlying legacy CM functions that 
       //  return an incorrect buffersize value on 
       //  DBCS/MBCS systems.
       // 
       while (!SetupDiGetDeviceRegistryProperty(
           hDevInfo,
           &DeviceInfoData,
           SPDRP_HARDWAREID,
           &DataT,
           (PBYTE)buffer,
           buffersize,
           &buffersize))
       {
 
           if (GetLastError() == 
               ERROR_INSUFFICIENT_BUFFER)
           {
               // Change the buffer size.
               if (buffer) LocalFree(buffer);
               // Double the size to avoid problems on 
               // W2k MBCS systems per KB 888609. 
              buffer = (char*)LocalAlloc(LPTR,buffersize * 2);
           }
           else
           {
               //Error handling here.
                           //printf("Error Details:[%s]\n",GetLastError());
               break;
           }
       }
                printf("Test Result:[%s]\n",buffer);
 
 
 
       if (buffer) LocalFree(buffer);
   }
 
 
   if ( GetLastError()!=NO_ERROR &&
        GetLastError()!=ERROR_NO_MORE_ITEMS )
   {
       // Error handling here.
           printf("Error Details:[%s]\n",GetLastError());
       return 1;
   }
 
   //  Cleanup
   SetupDiDestroyDeviceInfoList(hDevInfo);
 
 
   return 0;
lathareddy is offline   Reply With Quote
Thanked Users:
Strider (20-10-2009)
Reply

Tags
deviceid, hardwareid, vc++

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 08:13 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional