tags:

views:

23

answers:

1

I use the following code to enable/disable a device installed on my computer:

SP_PROPCHANGE_PARAMS params;

memset(&params, 0, sizeof(params));
devParams.cbSize = sizeof(devParams);

params.ClassInstallHeader.cbSize = sizeof(params.ClassInstallHeader);
params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
params.Scope       = DICS_FLAG_GLOBAL;
params.StateChange = DICS_DISABLE ;
params.HwProfile   = 0; // current profile

if(!SetupDiSetClassInstallParams(m_hDev, &m_hDevInfo,&params.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS))) 
{
     dwErr = GetLastError();
     return FALSE;
}

if(!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,m_hDev,&m_hDevInfo)) 
{
    dwErr = GetLastError();
    return FALSE;
}

return TRUE;

This code works perfectly only for those devices that can also be disabled by using Windows Device Manager, and won't work for some un-disabled devices such as my cpu device: Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz.

So the problem is how to determine if a device can be disabled or not programmatically? Is there any API to realize this goal? Thank you!

A: 

Hi Hans, thanks for your quick reply! I need to go through all the devices listed in Windows Device Manager, and determine which devices can be disabled and which can not be disabled.