0

I want to disable/enable all usb ports at once.
I tried the following:

Changed the registry (with admin privileges):

//disable USB storage...
Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4, Microsoft.Win32.RegistryValueKind.DWord); 

//enable USB storage...
Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 3, Microsoft.Win32.RegistryValueKind.DWord);

I also tried Hardware Helper Library for C# - even not detecting the devices
and Win32 API function to programmatically enable/disable device

I am using windows 8.1 64bit if it matters, and I compile the code with platform target = any CPU if it matters again.

EDIT:
Still not working.
I want to block/disable all the usb devices then even connect in the future and not only the current.
Can anyone help me?

Would appreciate your help.

Community
  • 1
  • 1
Ron
  • 3,677
  • 16
  • 69
  • 117

2 Answers2

0

That registry key prevents the USBSTOR driver from loading. It won't unload it if it is already in use. So you will not see any effect until after reboot.

Ben Voigt
  • 260,885
  • 36
  • 380
  • 671
  • Yes I know, I dont want to disable USB storage, I want to disable all kind of USB devices – Ron Dec 12 '13 at 15:30
  • @Ron: Same approach should work with `USBEHCI`, `USBHUB`, `USBXHCI`, `USBHUB3`, with the same limitation -- a reboot is needed to make it fully effective. – Ben Voigt Dec 12 '13 at 15:33
  • where did you bring the services name from, how do I know what each service affect... Is there any runtime method (one that doesnt require reboot?) – Ron Dec 12 '13 at 16:16
  • In Device Manager, pick a USB device, then Properties -> Driver -> Driver Details will list the drivers used. If you put device manager into "View by Connection" instead of "View by Type", then you will see which are the devices that all USB support depends on. – Ben Voigt Dec 12 '13 at 16:53
  • The instantaneous method is to use the SetupDi* API to set devices to disabled, but this needs to be done per-device, instead of per-driver. And only applies to devices already in the system; you'll need to repeat it if more devices appear (but it is unusual for new host controllers to appear, and with those disabled, new widgets can't be recognized). – Ben Voigt Dec 12 '13 at 16:56
  • Some virtual machine software appears to be using an even better way, which can associate individual widgets to either the OS driver or the VM forwarding driver -- for example VMWare Workstation does this. I'm not sure of the details; I think that filter drivers are involved. – Ben Voigt Dec 12 '13 at 16:58
  • Well, as far as I understand, I need to detect when USB device is connected and then disable/enable it. Seems like hard work. – Ron Dec 13 '13 at 17:40
  • @Ron: If the computer doesn't have PCI hotplug (such as an ExpressCard slot) then USB controllers can't be added on the fly, and it will be sufficient to disable all of them. – Ben Voigt Dec 13 '13 at 18:35
0

make USBSTOR value to 4 and restart the PC. Another way is to disable in BIOS. Most of the computer manufacturers support this. But it will disable not only storage but all.

SAKEER T
  • 11
  • 2