Hello, I am trying to disable a HID keyboard by using this commands:
SP_PROPCHANGE_PARAMS spPropChangeParams;
spPropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
spPropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
spPropChangeParams.Scope = DICS_FLAG_GLOBAL;
spPropChangeParams.StateChange = state; //(state = DICS_DISABLE)
SetupDiSetClassInstallParams(DeviceInfoSet, &DeviceInfoData, (SP_CLASSINSTALL_HEADER*)&spPropChangeParams, sizeof(spPropChangeParams));
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DeviceInfoSet, &DeviceInfoData);
After SetupDiCallClassInstaller I got 3758096945(ERROR_NOT_DISABLEABLE) from GetLastError(). This is logical, since in device manager I cannot see disable device option. But I discovered that whenever I click “restart port” in https://uwe-sieber.de/misc_tools_e.html#restartusbport keyboard disappears from device manager. During restarting port process I observe that 2 WM_DEVICECHANGE messages occur. DBT_DEVICEREMOVECOMPLETE and DBT_DEVNODES_CHANGED.
After those, I try to run above commands with state=DICS_ENABLE and SetupDiCallClassInstaller returns 0 as GetLastError return value. Finally I got DBT_DEVNODES_CHANGED and DBT_DEVICEARRIVAL events.
Before executing DICS_DISABLE command I have DN_DISABLEABLE in status though:
https://preview.redd.it/cpi371p366j61.png?width=3063&format=png&auto=webp&s=1b849638606197a62fc965e96aab5942ec72a717
After Restarting Port I have this (CM_PROB_DISABLED) line(DN_DISABLEABLE is among statuses of device again.):
https://preview.redd.it/2jf1m0p366j61.png?width=3129&format=png&auto=webp&s=09de3b8f0201eda9ad8cada346e109138048ef79
Question 1 : Why is DN_DISABLEABLE in statuses even though I cannot see disable device in right click menu of that device in Device Manager?
Qusetion 2: Why IOCTL_USB_HUB_CYCLE_PORT (restarting port) makes it work?
Question 3: Is there another way to do this on User Space? Should I switch to kernel space? I saw this post but things might have changed maybe?
Question 4: After restarting port I see that USB Composite Device Changes it state in Device Manager. And it supports “enable device” on right click. . But there was no “disable device” before that. Why is that?
Thank you in advance.