2

I used SetupDiSetClassInstallParams and SetupDiCallClassInstaller to disable specific USB device.

SP_PROPCHANGE_PARAMS params;

params.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
params.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
params.StateChange = DICS_DISABLE;

// SP_DEVINFO_DATA - Info.DevInfoData 
if (!SetupDiSetClassInstallParams(hDevInfo, &(Info.DevInfoData),&params.ClassInstallHeader, sizeof(params))) {
    Error = GetLastError();
    return Error;
}

if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &(Info.DevInfoData))) {
    Error = GetLastError(); // error here
}

This approach works to all devices, except keyboard. If i try to disable her this way ERROR_NOT_DISABLEABLE returned. But after reboot keyboard will be disabled.

Before disabling, flags DN_DISABLEABLE and DN_REMOVABLE seted for this device, checked by function CM_Get_DevNode_Status. What i am doing wrong?

  • why you not simply direct call [`CM_Disable_DevNode`](https://msdn.microsoft.com/en-us/library/windows/hardware/ff537996(v=vs.85).aspx) – RbMm Mar 06 '18 at 18:33
  • @RbMn becouse i did not know about this function, and used SetupDiSetClassInstallParams to enable devices too. Tried CM_Disable_DevNode to disable, its gives error but it works properly after reboot, this can be a solution, thanks a lot. – Vitaliy Lutsushyn Mar 06 '18 at 18:50
  • strongly say `SetupDiCallClassInstaller` call `CM_Disable_DevNode` internally but we can and direct call it yourself. despite in documentation `CM_DISABLE_PERSIST` used from win10 only - in my test `CM_Disable_DevNode` called when we use *disable* menu item from device manager and effect persist after reboot, even without this flag. which *CR_* error you got ? – RbMm Mar 06 '18 at 19:02
  • @RbMn with and without flag CM_DISABLE_PERSIST i got CR_NOT_DISABLEABLE. With flag all the same: keyboard working until reboot or pull USB out of port and and back – Vitaliy Lutsushyn Mar 06 '18 at 19:33
  • 1
    error code say - the device can not be disabled now. this is not your error. simply device not support this. call to `CM_Disable_DevNode` is correct. but not all devices support it – RbMm Mar 06 '18 at 19:38
  • @RbMm yea, even device manager dont allow me to disabe keyboard, but flags DN_DISABLEABLE and DN_REMOVABLE setted – Vitaliy Lutsushyn Mar 06 '18 at 19:46
  • *even device manager don`t allow me to disabe keyboard* - but device manager also call *CM_Disable_DevNode* - no another api for do this. and no different who call it - your process (if it have admin rights and high intergity or devmgmt) – RbMm Mar 06 '18 at 19:48
  • @RbMm i mean manager know that keyboard cannot be disabled, in spite of flags that i get – Vitaliy Lutsushyn Mar 06 '18 at 19:55

1 Answers1

0

This device don't support disabling