How to control power to USB ports using batch

23,842

Solution 1

You would need external hardware, such as a USB controlled relay. Windows itself does not provide a API or option to allow the power pins of USB ports to be switched off. This has been answered previously here and summarized history here.

Solution 2

Analysis of the problem

Since Vista, USB devices remain powered-on even after they are safely removed.

The Microsoft article USB Port Remains Active for Disabled or Safely Removed USB Device describes this new behavior :

In Windows XP and Windows Server 2003, when a USB device is marked as Removed, the USB hub port to which it is connected is Disabled. When the port is Disabled, no further USB traffic is sent to the device.

In Windows Vista, Windows Server 2008, Windows 7, and Windows Server 2008 R2, when a USB device is marked as Removed, the USB hub port to which it is connected is not Disabled.

I believe this behavior is what you are trying to change, in order to power-down devices that you have removed.

Solution

Power-down cannot be done via a batch script, but it can be returned to its XP behavior by modifying the registry, either as global setting for all USB devices or per-device.

To apply the workaround globally for all enumerated USB devices,
add a REG_DWORD value named DisableOnSoftRemove that has a value of 1 to the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\usbhub\HubG.

To apply the workaround for a specific device,
add a REG_DWORD value named DisableOnSoftRemove that has a value of 1 to the following registry subkey:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\usbflags\vvvvpppprrrr
where vvvv is the device's Vendor ID, pppp is the device's Product ID, and rrrr is the device's Revision number (found in Device Manager).

Solution 3

There is a powershell module that you can use to e.g. disable devices.

With this you could stop the operating system from using the USB ports. But this doesn't kill the power supply to these ports. Because that is in general not possible without modifying the hardware.

Only shutting down the computer might cut the power. Some computers have sleep-and-charge ports. Those provide power even if the computer is switched off (as long as there is a mains connection or a battery with sufficient charge available).

Share:
23,842

Related videos on Youtube

09stephenb
Author by

09stephenb

Updated on September 18, 2022

Comments

  • 09stephenb
    09stephenb over 1 year

    How can I toggle the power to a USB port on/off using batch or the command line? I am using Windows 8 to do this. Does anyone know what I could do? I have 4 USB ports.

  • 09stephenb
    09stephenb about 10 years
    This doesn't use batch or command line.
  • Daniel B
    Daniel B about 10 years
    Depending on the means of control, it could. Still, it's not possible as is. USB ports cannot be switch off. There's simply no such facility.