Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a programm that can detect HID class USB whit this command

static const GUID GuidInterfaceList[] =
{ 0x4d1e55b2, 0xf16f, 0x11Cf, { 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } },

but i need to make it more limit only for Magnetic card reader How can do it ? means i don't want let usb port to detect USB Mass Storage or keyboard or else if anyone has idea let me know pls tnx
Posted
Updated 16-Nov-13 23:09pm
v8
Comments
OriginalGriff 17-Nov-13 4:22am    
Stop bumping your question.
It's rude, it's unnecessary, and it's a weekend.
Changing your question to add information is fine, but just changing it to keep it at the top of the page is just going to annoy people, and reduce the chances of you getting an answer.
hooman khebrat 17-Nov-13 5:11am    
you are right ,
ok .
JJMatthews 19-Nov-13 3:02am    
I can post a function I wrote a while ago that enumerates all usb hubs on a system if you would like? You will just have to change it a little to look for your card readers.
hooman khebrat 19-Nov-13 6:23am    
Yes,please.
Thank you so much

1 solution

Here it is, if I can help with any questions I will.

//===============================================================================
// USBHubArray.cpp : 
//===============================================================================
#include "stdafx.h"
#include "USBHubArray.h"

#include "..\\COMMON\\Registry.h"

#include <cfg.h>
#include <cfgmgr32.h>
#include <Dbt.h>
#include <setupapi.h>
#pragma comment (lib, "Setupapi.lib")

... Rest of class (CUSBHubArray) omitted for clarity

BOOL CUSBHubArray::Enum(CString* pError/*=NULL*/)
{
	Clear();

	// Create a HDEVINFO with all usb hubs.  We cannot use the DIGCF_PRESENT
	//  flag here, for some reason external usb hubs (which is the only thing 
	//  we care about at the moment) that are disabled will not be returned in 
	//  the results.  We will search for all registered usb hubs and then 
	//  determine their type (internal/external) and their state.

	HDEVINFO hDevices = SetupDiGetClassDevs(
		&GUID_DEVINT_USB_HUB, 
		0, 0, DIGCF_DEVICEINTERFACE);
    if(hDevices == INVALID_HANDLE_VALUE)
	{
		if(pError)
			*pError = GetLastWin32Error(
				_T("CUSBHubArray::Enum"), 
				_T("SetupDiGetClassDevs")
			);
		return FALSE;
	}

	// Make bigass buffer 
	const unsigned int PROP_BUFF_SZ = 1000;
	LPTSTR pBuffer = (LPTSTR)LocalAlloc(LPTR, PROP_BUFF_SZ);
	ASSERT(pBuffer);
	memset(pBuffer, 0, PROP_BUFF_SZ);

    // Enumerate 
	SP_DEVINFO_DATA did = {0};
	did.cbSize = sizeof(SP_DEVINFO_DATA);
	for(DWORD dw = 0; SetupDiEnumDeviceInfo(hDevices, dw, &did); dw++)
	{
		// Here we must go by the device name, the service name is 
		//   the same for all usb hubs; internal (root) and external
		if(!SetupDiGetDeviceRegistryProperty(hDevices, &did, 
			SPDRP_DEVICEDESC, NULL, (PBYTE)pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceRegistryProperty")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}

		// Look for generic external hub name.  In the future this may need to be updated:
		//  if we must support another language or if the driver is updated/changed 
		if( (_tcsstr(pBuffer, _T("Standard-USB-Hub")) == 0) && // English OS
			(_tcsstr(pBuffer, _T("Generic USB Hub"))  == 0) )  // Deutsch OS
			continue;

		// Found a connected usb hub - read all properties that we need
		CUSBHubItem* pHubInfo = new CUSBHubItem;
		Add(pHubInfo);

		// See if device is present
		ULONG ulProblem = 0; // Present Disabled - 0x00000016 / Present Enabled - 0x00000000	
		ULONG ulStatus = 0;  //	Present Disabled - 0x01806400 / Present Enabled - 0x0180600a
		CONFIGRET cr = CM_Get_DevNode_Status(&ulStatus, &ulProblem, (DEVINST)did.DevInst, 0);
		if(cr & CR_FAILURE)
			pHubInfo->m_bPresent = false;

		// Check if device is disabled
		if(ulProblem & CM_PROB_DISABLED)
			pHubInfo->m_bDisabled = true;

		// Save device name
		pHubInfo->m_cstrDeviceName = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Read device instance id
		if(!SetupDiGetDeviceInstanceId(hDevices, 
			&did, pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceInstanceId")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}
		pHubInfo->m_cstrInstanceID = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Read hardware id
		if(!SetupDiGetDeviceRegistryProperty(hDevices, &did, 
			SPDRP_HARDWAREID, NULL, (PBYTE)pBuffer, PROP_BUFF_SZ, NULL))
		{
			if(pError)
				*pError = GetLastWin32Error(
					_T("CUSBHubArray::Enum"), 
					_T("SetupDiGetDeviceRegistryProperty")
				);
			LocalFree(pBuffer);
			SetupDiDestroyDeviceInfoList(hDevices);
			return FALSE;
		}
		pHubInfo->m_cstrHardwareID = pBuffer;
		memset(pBuffer, 0, PROP_BUFF_SZ);

		// Figure out hub's registry key
		CString strRegKey = _T("SYSTEM\\CurrentControlSet\\Enum\\USB\\");
		strRegKey += pHubInfo->m_cstrInstanceID.Mid(4);
		pHubInfo->m_cstrRegKey = strRegKey;

		// Read ParentIdPrefix from registry
		CString strVal = _T("");
		GetRegStr(HKEY_LOCAL_MACHINE, strRegKey, 
			_T("ParentIdPrefix"), strVal.GetBuffer(MAX_PATH));
		strVal.ReleaseBuffer();
		pHubInfo->m_cstrPIDP = strVal;

		// Read symbolic name from registry
		CString strDPRegKey = strRegKey;
		strDPRegKey += _T("\\Device Parameters");
		GetRegStr(HKEY_LOCAL_MACHINE, strDPRegKey, 
			_T("SymbolicName"), strVal.GetBuffer(MAX_PATH));
		strVal.ReleaseBuffer();
		pHubInfo->m_cstrSymbName = strVal;

		// Read GE Number from registry
		pHubInfo->m_dwGENumber = GetRegDWORD(HKEY_LOCAL_MACHINE, strDPRegKey, _T("GENumber"), 0);
	}

	// Cleanup
	LocalFree(pBuffer);
	SetupDiDestroyDeviceInfoList(hDevices);

	return TRUE;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900