Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

Disabling not disableable keyboard

lapaz17lapaz17 Member Posts: 7

Hello, I am trying to disable a HID keyboard by using this commands:

    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 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:

After Restarting Port I have this (CM_PROB_DISABLED) line(DN_DISABLEABLE is among statuses of device again.):

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.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE