disable/enable a device in device manager (Win10)
Posted: Fri Dec 18, 2020 2:23 am
Anyone a idea how to enable and disable a device in the device manager with PureBasic?
I have two special devices for the same USB hardware that i need to disable when i did not use it and of course than enable to use them (unplug is no option). I want to make this with a little Tool over a Tray Icon Menu beside the windows clock (bottom right).
The Hardware-IDs are always the same and known, if that helps.
I also found this older code that sounds like what i need but the needed header files are offline (404 at the download link).
viewtopic.php?f=5&t=65328
And also no example on RSBasics WinAPI side.
---------------
Edit: found this older code: viewtopic.php?f=13&t=50669
Also i found this side, it says you should use cfgmgr32.dll instead, so i changed my code to this:
https://docs.microsoft.com/en-us/window ... ble-device
Edit 2: works now, you need Admin Rights for *F2/*F3.
I have two special devices for the same USB hardware that i need to disable when i did not use it and of course than enable to use them (unplug is no option). I want to make this with a little Tool over a Tray Icon Menu beside the windows clock (bottom right).
The Hardware-IDs are always the same and known, if that helps.
I also found this older code that sounds like what i need but the needed header files are offline (404 at the download link).
viewtopic.php?f=5&t=65328
And also no example on RSBasics WinAPI side.
---------------
Edit: found this older code: viewtopic.php?f=13&t=50669
Also i found this side, it says you should use cfgmgr32.dll instead, so i changed my code to this:
https://docs.microsoft.com/en-us/window ... ble-device
Code: Select all
EnableExplicit
Define *F1, *F2, *F3
Define devhandle.l, id.s
If OpenLibrary(1,"cfgmgr32.dll")
*F1 = GetFunction(1, "CM_Locate_DevNodeW")
*F2 = GetFunction(1, "CM_Disable_DevNode")
*F3 = GetFunction(1, "CM_Enable_DevNode")
;look in registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum
;to find Identifiers for PCI/USB ... Devices
id.s = "USB\VID_045E&PID_0659&MI_03\8&23fc3de6&0&0003" ;sample USB id
Debug CallFunctionFast(*F1, @devhandle, @id, 0)
Debug CallFunctionFast(*F2 ,devhandle, 0) ;disable device
;Debug CallFunctionFast(*F3 ,devhandle, 0) ;enable device
CloseLibrary(1)
EndIf