SetupDiSetClassInstallParams and DICS_ENABLE doesn't work as expected on Windows 7

The goal is to been able to enable or diseable a USB device in a small test application.The following code works on Windows XP and Vista. It doesn’t on Windows 7. Does anybody face the same kind of issue?

I got the code from here: https://www.osronline.com/showThread.CFM?link=82625

inline bool EnableDevice(const HDEVINFO Devs, const PSP_DEVINFO_DATA DevInfo, const bool bEnable)

{

bool reboot = false;

// ControlCallback function body

SP_PROPCHANGE_PARAMS pcp;

SP_DEVINSTALL_PARAMS devParams;

if (bEnable)

{

//

// enable both on global and config-specific profile

// do global first and see if that succeeded in enabling the device

// (global enable doesn’t mark reboot required if device is still

// disabled on current config whereas vice-versa isn’t true)

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_ENABLE;

pcp.Scope = DICS_FLAG_GLOBAL;

pcp.HwProfile = 0;

//

// don’t worry if this fails, we’ll get an error when we try config-

// specific.

if (SetupDiSetClassInstallParams(Devs, DevInfo,

&pcp.ClassInstallHeader, sizeof(pcp)))

{

SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,Devs,DevInfo);

}

//

// now enable on config-specific

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_ENABLE;

pcp.Scope = DICS_FLAG_CONFIGSPECIFIC;

pcp.HwProfile = 0;

}

else

{

//

// operate on config-specific profile

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_DISABLE;

pcp.Scope = DICS_FLAG_CONFIGSPECIFIC;

pcp.HwProfile = 0;

}

if (!SetupDiSetClassInstallParams(Devs, DevInfo, &pcp.ClassInstallHeader,

sizeof(pcp)) ||

!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,Devs,DevInfo))

{

TESTTRACE(_T("Device state changed to "));

//_ASSERT(false);

}

else

{

//

// see if device needs reboot

//

devParams.cbSize = sizeof(devParams);

if (SetupDiGetDeviceInstallParams(Devs,DevInfo,&devParams) &&

(devParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)))

{

reboot = true;

}

else

{

//

// appears to have succeeded

//

}

}

if (reboot)

TESTTRACE(_T(“Reboot request!”));

return !reboot;

}

How does it fail? What error codes are returned? What do the logs say?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@logitech.com
Sent: Thursday, March 25, 2010 2:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] SetupDiSetClassInstallParams and DICS_ENABLE doesn’t work as expected on Windows 7

The goal is to been able to enable or diseable a USB device in a small test application.The following code works on Windows XP and Vista. It doesn’t on Windows 7. Does anybody face the same kind of issue?

I got the code from here: https://www.osronline.com/showThread.CFM?link=82625

inline bool EnableDevice(const HDEVINFO Devs, const PSP_DEVINFO_DATA DevInfo, const bool bEnable)

{

bool reboot = false;

// ControlCallback function body

SP_PROPCHANGE_PARAMS pcp;

SP_DEVINSTALL_PARAMS devParams;

if (bEnable)

{

//

// enable both on global and config-specific profile

// do global first and see if that succeeded in enabling the device

// (global enable doesn’t mark reboot required if device is still

// disabled on current config whereas vice-versa isn’t true)

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_ENABLE;

pcp.Scope = DICS_FLAG_GLOBAL;

pcp.HwProfile = 0;

//

// don’t worry if this fails, we’ll get an error when we try config-

// specific.

if (SetupDiSetClassInstallParams(Devs, DevInfo,

&pcp.ClassInstallHeader, sizeof(pcp)))

{

SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,Devs,DevInfo);

}

//

// now enable on config-specific

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_ENABLE;

pcp.Scope = DICS_FLAG_CONFIGSPECIFIC;

pcp.HwProfile = 0;

}

else

{

//

// operate on config-specific profile

//

pcp.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

pcp.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;

pcp.StateChange = DICS_DISABLE;

pcp.Scope = DICS_FLAG_CONFIGSPECIFIC;

pcp.HwProfile = 0;

}

if (!SetupDiSetClassInstallParams(Devs, DevInfo, &pcp.ClassInstallHeader,

sizeof(pcp)) ||

!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,Devs,DevInfo))

{

TESTTRACE(_T("Device state changed to "));

//_ASSERT(false);

}

else

{

//

// see if device needs reboot

//

devParams.cbSize = sizeof(devParams);

if (SetupDiGetDeviceInstallParams(Devs,DevInfo,&devParams) &&

(devParams.Flags & (DI_NEEDRESTART|DI_NEEDREBOOT)))

{

reboot = true;

}

else

{

//

// appears to have succeeded

//

}

}

if (reboot)

TESTTRACE(_T(“Reboot request!”));

return !reboot;

}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I’m having the same issue. It works in XP and Vista, but not Windows 7. I’m adding virtual devices. Usually the call above will eventually trigger PnP to call my device’s Add Device function. But on Windows 7 no call occurs.