Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <setupapi.h>
- #include <devguid.h>
- #include <regstr.h>
- #define TOTALBYTES 8192
- #define BYTEINCREMENT 4096
- #define MODEMFOUND 1
- #define MODEMNOTFOUND 0
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- typedef BOOL ( *fptr1 ) ( PCWSTR , DWORD, PVOID );
- fptr1 SetupUninstallOEMInf;
- HDEVINFO hDevInfo;
- SP_DEVINFO_DATA DeviceInfoData;
- DWORD i;
- int DeviceFound_Flag = 0;
- // initialisations for RegQuery
- DWORD BufferSize = TOTALBYTES;
- DWORD cbData;
- DWORD dwRet;
- BOOL Modem_Flag = MODEMNOTFOUND;
- PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
- cbData = BufferSize;
- HINSTANCE hinstLib = LoadLibrary( "Setupapi.dll" );
- if ( hinstLib == NULL ) {
- printf ("Load library failed\n");
- }
- SetupUninstallOEMInf = (fptr1)GetProcAddress(hinstLib, "SetupUninstallOEMInfA");
- hDevInfo = SetupDiGetClassDevs ( NULL,
- NULL, // Enumerator
- 0,
- DIGCF_ALLCLASSES );
- if (hDevInfo == INVALID_HANDLE_VALUE)
- {
- // Insert error handling here.
- //MessageBox(NULL, "Device not found!!", TEXT ( "Device Status!!" ),
- //0 );
- return 1;
- }
- // Enumerate through all devices in Set.
- DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
- if ( (SetupDiEnumDeviceInfo(hDevInfo,0,
- &DeviceInfoData ) == 0 ) ) {
- MessageBox(NULL, "Device not found!!", TEXT ( "Device Status!!" ),
- 0 );
- }
- for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
- &DeviceInfoData);i++)
- {
- DWORD DataT;
- LPTSTR buffer = NULL;
- DWORD buffersize = 0;
- LPTSTR temp_array = NULL;
- //
- // 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 = LocalAlloc(LPTR,buffersize * 2);
- }
- else
- {
- // Insert error handling here.
- break;
- }
- }
- if ( buffer != NULL ) {
- if ( ( strnicmp ( buffer , "USB\\VID_16DE&PID_0010", strlen ("USB\\VID_16DE&PID_0010") ) == 0 ) ||
- ( strnicmp ( buffer , "USB\\VID_16DE&PID_001", strlen ("USB\\VID_16DE&PID_001") ) == 0 ) ||
- ( strnicmp ( buffer , "USB\\VID_16DE&PID_002", strlen ("USB\\VID_16DE&PID_002") ) == 0 ) ||
- ( strnicmp ( buffer , "USB\\VID_16DE&PID_003", strlen ("USB\\VID_16DE&PID_003") ) == 0 ) ) {
- DeviceFound_Flag = 1;
- HKEY hDeviceKey = SetupDiOpenDevRegKey ( hDevInfo, &DeviceInfoData,
- DICS_FLAG_GLOBAL,
- 0,
- DIREG_DRV,
- KEY_READ);
- dwRet = RegQueryValueEx (hDeviceKey, "InfPath", NULL, NULL , (LPBYTE) PerfData, &cbData );
- //printf ("%s\n", PerfData);
- ////////////////////////
- while( dwRet == ERROR_MORE_DATA )
- {
- // Get a buffer that is big enough.
- printf ("inside while loop\n");
- BufferSize += BYTEINCREMENT;
- PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize );
- cbData = BufferSize;
- //printf(".");
- dwRet = RegQueryValueEx ( hDeviceKey, "InfPath", NULL, NULL, (LPBYTE) PerfData, &cbData );
- }
- //printf("\n\nFinal buffer size is %d %s\n", BufferSize, PerfData);
- if( dwRet == ERROR_SUCCESS ) {
- }
- else printf ( "\nRegQueryValueEx failed (%d)\n", dwRet );
- printf ( "%s %s\n",buffer,PerfData );
- SetupUninstallOEMInf ( (PCWSTR)PerfData, 0, NULL );
- } else {
- continue;
- }
- }
- if (buffer)
- LocalFree(buffer);
- }
- if ( GetLastError()!=NO_ERROR &&
- GetLastError()!=ERROR_NO_MORE_ITEMS )
- {
- // Insert error handling here.
- return 1;
- }
- // Cleanup
- SetupDiDestroyDeviceInfoList(hDevInfo);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement