How to know if a device can be disabled or not?

Posted by user326498 on Stack Overflow See other posts from Stack Overflow or by user326498
Published on 2010-04-27T02:48:24Z Indexed on 2010/04/27 2:53 UTC
Read the original article Hit count: 289

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about win32

Related posts about devices