How to Disable USB Selective Suspend in Batch Script
USB Selective Suspend is a Windows power management feature that allows the operating system to individually power down USB ports that are idle, shutting off peripherals to conserve battery on laptops. While beneficial for mobile devices, it is a notorious culprit behind disappearing USB drives, intermittent mouse disconnections, and audio interface dropouts on desktop workstations.
In this guide, we will explore how to disable USB Selective Suspend using Batch Script by modifying the active power plan through the powercfg utility and, alternatively, through direct registry manipulation.
Understanding USB Selective Suspend
When USB Selective Suspend is enabled, Windows monitors each USB port individually. If a device on a given port has been idle for a certain period, Windows sends a "suspend" signal to that specific port, effectively cutting power to the device. When the device needs to communicate again, Windows sends a "resume" signal.
The problem arises when:
- External hard drives disconnect mid-transfer because the OS thinks they are "idle" between large sequential writes.
- Audio interfaces (DACs) produce clicks and pops when resuming from a suspended state.
- Wireless mouse receivers lose their connection, causing the cursor to freeze for 1-2 seconds.
Disabling this feature instructs Windows to keep all USB ports powered continuously, regardless of activity.
Method 1: Using POWERCFG (Active Power Plan)
The fastest way to disable USB Selective Suspend on the currently active power plan is to use the powercfg /change syntax, but unfortunately, there is no direct /change alias for this specific setting. Instead, we must use the /setacvalueindex and /setdcvalueindex commands targeting the USB subgroup.
Finding the Correct Subgroup and Setting GUIDs
The USB Selective Suspend setting lives under:
- Subgroup GUID:
2a737441-1930-4402-8d77-b2bebba308a3(USB settings) - Setting GUID:
48e6b7a6-50f5-4782-a5d4-53bb8f07e226(USB selective suspend setting)
The value is:
0= Disabled1= Enabled
The Script
@echo off
setlocal enabledelayedexpansion
echo Disabling USB Selective Suspend...
:: Get the GUID of the active power plan
set "active_guid="
for /f "tokens=*" %%L in ('powercfg /getactivescheme 2^>nul') do (
for /f "tokens=4" %%G in ("%%L") do (
set "candidate=%%G"
echo !candidate! | findstr /r "[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" >nul 2>&1
if !errorlevel! equ 0 set "active_guid=%%G"
)
)
if not defined active_guid (
echo [ERROR] Could not determine the active power plan GUID.
echo Ensure you are running this script as Administrator.
pause
exit /b 1
)
echo Active Power Plan GUID: %active_guid%
:: USB Subgroup and Setting GUIDs
set "usb_sub=2a737441-1930-4402-8d77-b2bebba308a3"
set "usb_suspend=48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
:: Disable for AC (Plugged In) - Value 0 = Disabled
powercfg /setacvalueindex %active_guid% %usb_sub% %usb_suspend% 0
if errorlevel 1 (
echo [ERROR] Failed to set AC value. Verify the subgroup and setting GUIDs.
pause
exit /b 1
)
:: Disable for DC (Battery) - Value 0 = Disabled
powercfg /setdcvalueindex %active_guid% %usb_sub% %usb_suspend% 0
if errorlevel 1 (
echo [ERROR] Failed to set DC value. Verify the subgroup and setting GUIDs.
pause
exit /b 1
)
:: Apply the changes
powercfg /setactive %active_guid%
echo.
echo [SUCCESS] USB Selective Suspend has been disabled.
echo USB devices will no longer be powered down when idle.
pause
Why We Call /setactive Again
After changing the value indexes, the new settings are written to the plan's configuration but may not be applied to the running system until the plan is "reactivated." Calling powercfg /setactive on the same GUID forces Windows to re-read all values and apply them immediately, without a reboot.
Method 2: Using POWERCFG with Aliases (Simpler Syntax)
Windows also supports human-readable aliases for some subgroups and settings, which can make scripts cleaner when available.
@echo off
setlocal enabledelayedexpansion
echo Disabling USB Selective Suspend (Simplified^)...
set "plan="
for /f "tokens=*" %%L in ('powercfg /getactivescheme 2^>nul') do (
for /f "tokens=4" %%G in ("%%L") do (
set "candidate=%%G"
echo !candidate! | findstr /r "[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" >nul 2>&1
if !errorlevel! equ 0 set "plan=%%G"
)
)
if not defined plan (
echo [ERROR] Could not determine the active power plan GUID.
pause
exit /b 1
)
:: Attempt using aliases first, fall back to raw GUIDs on failure
set "usb_sub_alias=SUB_USB"
set "usb_setting_alias=USBSELECTIVESUSPEND"
set "usb_sub_guid=2a737441-1930-4402-8d77-b2bebba308a3"
set "usb_setting_guid=48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
powercfg /setacvalueindex %plan% %usb_sub_alias% %usb_setting_alias% 0 >nul 2>&1
if errorlevel 1 (
echo Aliases not supported on this system. Using raw GUIDs...
powercfg /setacvalueindex %plan% %usb_sub_guid% %usb_setting_guid% 0
powercfg /setdcvalueindex %plan% %usb_sub_guid% %usb_setting_guid% 0
) else (
powercfg /setdcvalueindex %plan% %usb_sub_alias% %usb_setting_alias% 0
)
powercfg /setactive %plan%
echo [OK] Done.
pause
The alias SUB_USB is generally available on Windows 10 and later. The setting-level alias for USB Selective Suspend varies across Windows versions. The correct alias is USBSELECTIVESUSPEND (no spaces or mixed case). If you receive an "Invalid Parameters" error, the script above will automatically fall back to using the full GUIDs from Method 1. You can discover the available aliases on your system by running powercfg /query and examining the GUID Alias lines in the output.
Method 3: Registry-Based Approach (All Power Plans)
If you want to disable USB Selective Suspend across every power plan on the system (not just the active one), you can write directly to the registry. This is especially useful in enterprise deployment scripts where you cannot predict which power plan a user will select.
The power setting values for each plan are stored under:
HKLM\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\{PlanGUID}\{SubgroupGUID}\{SettingGUID}
This script iterates through all power plans on the system and sets the USB Selective Suspend value to 0 (disabled) for both AC and DC power states in each one.
@echo off
setlocal enabledelayedexpansion
echo Disabling USB Selective Suspend across all power plans...
set "usb_sub=2a737441-1930-4402-8d77-b2bebba308a3"
set "usb_suspend=48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
set "plan_count=0"
:: Iterate through all power plans and apply the setting to each
for /f "tokens=*" %%L in ('powercfg /list 2^>nul') do (
set "guid="
for /f "tokens=4" %%G in ("%%L") do (
set "candidate=%%G"
echo !candidate! | findstr /r "[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" >nul 2>&1
if !errorlevel! equ 0 set "guid=%%G"
)
if defined guid (
powercfg /setacvalueindex !guid! %usb_sub% %usb_suspend% 0 >nul 2>&1
powercfg /setdcvalueindex !guid! %usb_sub% %usb_suspend% 0 >nul 2>&1
echo Updated plan: !guid!
set /a plan_count+=1
)
)
:: Reactivate the current plan to apply changes immediately
for /f "tokens=*" %%L in ('powercfg /getactivescheme 2^>nul') do (
for /f "tokens=4" %%G in ("%%L") do (
set "candidate=%%G"
echo !candidate! | findstr /r "[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" >nul 2>&1
if !errorlevel! equ 0 powercfg /setactive %%G
)
)
echo.
echo [OK] USB Selective Suspend disabled across !plan_count! power plan(s^).
pause
To verify the change was applied, run the following command after the script completes:
powercfg /query %active_guid% 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226
Both "Current AC Power Setting Index" and "Current DC Power Setting Index" should show 0x00000000.
Creating a Toggle Script
For maximum flexibility, you can build a script that checks the current state and toggles between enabled and disabled.
@echo off
setlocal enabledelayedexpansion
:: Get active plan
set "plan="
for /f "tokens=*" %%L in ('powercfg /getactivescheme 2^>nul') do (
for /f "tokens=4" %%G in ("%%L") do (
set "candidate=%%G"
echo !candidate! | findstr /r "[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*-[0-9a-fA-F]*" >nul 2>&1
if !errorlevel! equ 0 set "plan=%%G"
)
)
if not defined plan (
echo [ERROR] Could not determine the active power plan.
pause
exit /b 1
)
set "usb_sub=2a737441-1930-4402-8d77-b2bebba308a3"
set "usb_suspend=48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
:: Read the current AC value via powercfg /query
set "current_val="
for /f "tokens=*" %%L in ('powercfg /query %plan% %usb_sub% %usb_suspend% 2^>nul ^| findstr /i "Current AC Power Setting Index"') do (
set "line=%%L"
)
if not defined line (
echo [ERROR] Could not read the current USB Selective Suspend value.
echo The setting may not exist on this system.
pause
exit /b 1
)
:: The line looks like: "Current AC Power Setting Index: 0x00000001"
:: Extract the hex value after "0x"
for /f "tokens=2 delims=x" %%V in ("!line:*0x=0x!") do set "hex_val=%%V"
:: Convert to a simple comparison (strip leading zeros)
set /a "current_val=0x!hex_val!" 2>nul
if !current_val! equ 1 (
echo USB Selective Suspend is currently ENABLED. Disabling...
powercfg /setacvalueindex %plan% %usb_sub% %usb_suspend% 0
powercfg /setdcvalueindex %plan% %usb_sub% %usb_suspend% 0
echo [OK] USB Selective Suspend DISABLED.
) else if !current_val! equ 0 (
echo USB Selective Suspend is currently DISABLED. Enabling...
powercfg /setacvalueindex %plan% %usb_sub% %usb_suspend% 1
powercfg /setdcvalueindex %plan% %usb_sub% %usb_suspend% 1
echo [OK] USB Selective Suspend ENABLED.
) else (
echo [ERROR] Unexpected value: !current_val!
pause
exit /b 1
)
powercfg /setactive %plan%
echo [OK] Setting toggled successfully.
pause
Common Mistakes
The Wrong Way: Using /change with a Non-Existent Alias
:: WRONG - There is no "usb-suspend-timeout" alias in /change
powercfg /change usb-suspend-timeout-ac 0
Unlike monitor-timeout-ac or disk-timeout-ac, USB Selective Suspend does not have a shorthand alias for the /change command. The command will fail with "Invalid Parameters." Always use /setacvalueindex with the specific GUIDs or supported aliases.
The Wrong Way: Using an Incorrect Setting Alias
:: WRONG - "UsbSelectiveSuspend" with mixed case is not a valid alias
powercfg /setacvalueindex %plan% SUB_USB UsbSelectiveSuspend 0
The powercfg alias system is case-insensitive for matching, but the actual registered alias string must exist exactly as Windows defines it. The alias UsbSelectiveSuspend with mixed casing is not how Windows registers this setting on most systems. Use USBSELECTIVESUSPEND or, for guaranteed compatibility, use the full setting GUID 48e6b7a6-50f5-4782-a5d4-53bb8f07e226. Run powercfg /query to verify which aliases are available on your target system.
The Correct Way: Use /setacvalueindex with GUIDs
Always target the specific GUIDs with the /setacvalueindex command for maximum compatibility:
:: CORRECT - Full GUIDs work on all Windows versions
powercfg /setacvalueindex %plan% 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
powercfg /setdcvalueindex %plan% 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
Best Practices
- Disable on workstations: If the machine is a desktop PC that is always plugged in, there is virtually no downside to disabling Selective Suspend entirely.
- Be cautious on laptops: Disabling this feature on battery-powered devices will reduce battery life. Consider only disabling the AC value and leaving the DC (battery) value enabled.
- Reactivate the plan: Always call
powercfg /setactiveafter modifying index values to force the updated configuration into memory immediately. - Validate the GUID: Always verify that the active plan GUID was successfully captured before using it in subsequent commands. An empty GUID variable will cause
powercfgto modify unintended settings or fail silently. - Use full GUIDs for portability: While aliases like
SUB_USBare convenient, they are not guaranteed to exist on all Windows editions and versions. Full GUIDs provide the most reliable cross-version compatibility. - Run as Administrator: Power plan modifications require elevated privileges. Include proper error handling for non-elevated execution.
Conclusion
Disabling USB Selective Suspend via Batch Script eliminates one of the most common causes of intermittent USB device disconnections on Windows. By targeting the active power plan's USB subgroup with powercfg /setacvalueindex and /setdcvalueindex, administrators can ensure that all USB ports remain continuously powered. For broader deployments affecting all plans, iterating through every plan GUID returned by powercfg /list provides comprehensive coverage across any power configuration a user might select.