void SMNetworkAdapterSettings::_FindAdvancedSettings(HDEVINFO* /*devInfo*/, SP_DEVINFO_DATA* devInfoData, SMRegistryKey* netDeviceKey, SMRegistryKey* advancedSettingsKey) const
{
	// Open Registry key for all network devices ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}". {4D36E972-E325-11CE-BFC1-08002BE10318} is key for all network devices.)
	HKEY classKey = SetupDiOpenClassRegKeyEx(&devInfoData->ClassGuid, KEY_QUERY_VALUE, DIOCR_INSTALLER/*DIOCR_INTERFACE*/, NULL, NULL);
	//HKEY classKey = SetupDiOpenClassRegKeyEx(&devInfoData->ClassGuid, KEY_READ, DIOCR_INSTALLER/*DIOCR_INTERFACE*/, NULL, NULL);
	if ( INVALID_HANDLE_VALUE == classKey )
		throw SMRuntimeException(::GetLastError());
	
	SMRegistryKey netDevicesRegKey(classKey, "");

	SMString hwID = _hardwareId;
	hwID.MakeUpper();

	//////////////////////////////////////////////////////////////////////////
	// Search entry for our device. We will use _hardwareId to compare device's entries.
	SMString key;
	DWORD valueIndex = 0;
	while (netDevicesRegKey.EnumKey( valueIndex++, key))
	{
		netDeviceKey->Open(netDevicesRegKey, key);

		if (netDeviceKey->IsValid())
		{
			SMString componentId = netDeviceKey->GetString( COMPONENT_ID );
			componentId.MakeUpper();

			if ( -1 != componentId.Find(hwID.DataW()) 
				|| -1 != hwID.Find(componentId.DataW()) )
			{ // we've found entry for network device with ID equal to _hardwareId 

				// Open sub-key with advanced settings. If they are exist, they are under "Ndi\\params".
				HRESULT hrAdvancedSettingsArePresent = advancedSettingsKey->Open(*netDeviceKey, SUBPATH_TO_ADVANCED_SETTINGS);
				if ( FAILED(hrAdvancedSettingsArePresent) )
				{
					SM_LOG(E_FAIL, SMTRACE, __FUNCTION__ << " Failed open registry key !");
					throw SMRuntimeException(::GetLastError());
				}

				break;
			}
		}
	} // while (netDevicesRegKey.EnumKey( valueIndex++, key))
}
Ejemplo n.º 2
0
static
VOID
EnumDeviceClasses(
    HWND hTreeView,
    HTREEITEM hRoot,
    PDEVCLASS_ENTRY pClassArray,
    ULONG ClassCount)
{
    WCHAR ClassName[MAX_DEV_LEN];
    WCHAR ClassDesc[MAX_DEV_LEN];
    PDEVCLASS_ENTRY pClass;
    ULONG ClassIndex;
    DWORD dwSize;
    LONG lSize;
    HKEY hKey;
    CONFIGRET cr;

    for (ClassIndex = 0; ClassIndex < ClassCount; ClassIndex++)
    {
        pClass = &pClassArray[ClassIndex];

        cr = CM_Enumerate_Classes(ClassIndex,
                                  &pClass->ClassGuid,
                                  0);
        if (cr == CR_NO_SUCH_VALUE)
            return;

        dwSize = MAX_CLASS_NAME_LEN;
        if (!SetupDiClassNameFromGuid(&pClass->ClassGuid,
                                      ClassName,
                                      dwSize,
                                      &dwSize))
        {
            ClassName[0] = _T('\0');
        }

        if (!SetupDiGetClassImageIndex(&ImageListData,
                                       &pClass->ClassGuid,
                                       &pClass->ClassImage))
        {
            /* FIXME: can we do this?
             * Set the blank icon: IDI_SETUPAPI_BLANK = 41
             * it'll be image 24 in the imagelist */
            pClass->ClassImage = 24;
        }

        hKey = SetupDiOpenClassRegKeyEx(&pClass->ClassGuid,
                                        MAXIMUM_ALLOWED,
                                        DIOCR_INSTALLER,
                                        NULL,
                                        0);
        if (hKey != INVALID_HANDLE_VALUE)
        {
            lSize = MAX_DEV_LEN;
            if (RegQueryValue(hKey,
                              NULL,
                              ClassDesc,
                              &lSize) != ERROR_SUCCESS)
            {
                ClassDesc[0] = _T('\0');
            }

            RegCloseKey(hKey);
        }

        pClass->hItem = InsertIntoTreeView(hTreeView,
                                           hRoot,
                                           (ClassDesc[0] != _T('\0')) ? ClassDesc : ClassName,
                                           NULL,
                                           pClass->ClassImage,
                                           0);
    }
}
Ejemplo n.º 3
0
static INT
EnumDeviceClasses(INT ClassIndex,
                  LPWSTR DevClassName,
                  LPWSTR DevClassDesc,
                  BOOL *DevPresent,
                  INT *ClassImage)
{
    GUID ClassGuid;
    HKEY KeyClass;
    WCHAR ClassName[MAX_STR_SIZE];
    DWORD RequiredSize = MAX_STR_SIZE;
    UINT Ret;

    *DevPresent = FALSE;
    *DevClassName = L'\0';

    Ret = CM_Enumerate_Classes(ClassIndex,
                               &ClassGuid,
                               0);
    if (Ret != CR_SUCCESS)
    {
        /* All classes enumerated */
        if(Ret == CR_NO_SUCH_VALUE)
        {
            hDevInfoTypes = NULL;
            return -1;
        }

        if (Ret == CR_INVALID_DATA)
        {
            ; /* FIXME: What should we do here? */
        }

        /* Handle other errors... */
    }

    if (SetupDiClassNameFromGuid(&ClassGuid,
                                 ClassName,
                                 RequiredSize,
                                 &RequiredSize))
    {
        lstrcpy(DevClassName, ClassName);
    }

    if (!SetupDiGetClassImageIndex(&ImageListData,
                                   &ClassGuid,
                                   ClassImage))
    {
        /* FIXME: Can we do this?
         * Set the blank icon: IDI_SETUPAPI_BLANK = 41
         * It'll be image 24 in the imagelist */
        *ClassImage = 24;
    }

    /* Get device info for all devices of a particular class */
    hDevInfoTypes = SetupDiGetClassDevs(&ClassGuid,
                                   NULL,
                                   NULL,
                                   DIGCF_PRESENT);
    if (hDevInfoTypes == INVALID_HANDLE_VALUE)
    {
        hDevInfoTypes = NULL;
        return 0;
    }

    KeyClass = SetupDiOpenClassRegKeyEx(&ClassGuid,
                                        MAXIMUM_ALLOWED,
                                        DIOCR_INSTALLER,
                                        NULL,
                                        0);
    if (KeyClass != INVALID_HANDLE_VALUE)
    {

        LONG dwSize = MAX_STR_SIZE;

        if (RegQueryValue(KeyClass,
                          NULL,
                          DevClassDesc,
                          &dwSize) != ERROR_SUCCESS)
        {
            *DevClassDesc = L'\0';
        }
    }
    else
    {
        return -3;
    }

    *DevPresent = TRUE;

    RegCloseKey(KeyClass);

    return 0;
}