@Paul Black,
I think there is a bug in your code, I propose to add some (so hated) goto at the end of each option:
Code:
@echo off
:: ##########################################################################################################
:: # Title : Turn On Or Off USB Selective Suspend #
:: # Created By: Paul Black at TenForums.com/members/paul-black.html #
:: # Created In: November 2020 #
:: # Tutorial : https://www.tenforums.com/tutorials/73187-turn-off-usb-selective-suspend-windows-10-a.html #
:: ##########################################################################################################
title Turn On Or Off USB Selective Suspend - Written by Paul Black.
mode con: cols=80 lines=25 & color 17
set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs") && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /b)
%windir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || ( echo. & echo ERROR: This Batch file MUST be run in an ELEVATED cmd prompt [ Administrator ] & echo. & echo Right-click the Batch file and click ^<Run as administrator^>. & echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & goto :Exit )
:Options
echo. & echo ==============================================================================
echo Turn On Or Off USB Selective Suspend.
echo ==============================================================================
echo. & echo Options:
echo. & echo [0] EXIT this Program.
echo. & echo [1] On Battery - Enabled [ Default ].
echo [2] On Battery - Disabled.
echo. & echo [3] Plugged In - Enabled [ Default ].
echo [4] Plugged In - Disabled.
echo. & echo ==============================================================================
echo.
CHOICE /N /C 01234 /M ">Enter an Option:"
if %errorlevel%==5 goto Plugged_Dis
if %errorlevel%==4 goto Plugged_Ena
if %errorlevel%==3 goto Battery_Dis
if %errorlevel%==2 goto Battery_Ena
if %errorlevel%==1 goto Exit
goto :Options
:Battery_Ena
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 1
echo. Battery Enabled
goto :Complete
:Battery_Dis
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
echo. Battery Disabled
goto :Complete
:Plugged_Ena
powercfg /SETACVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 1
echo. Plugged Enabled
goto :Complete
:Plugged_Dis
powercfg /SETACVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
echo. Plugged Disabled
goto :Complete
:Complete
echo. & echo Processing COMPLETE.
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & goto :Exit
:Exit
I will also try to mix this idea with the one in Remove 'USB selective suspend setting' in Power Options in Windows
Berbigou (it's my first post here, I hope I did nothing wrong)
- - - Updated - - -
Here is a mixed tool from this thread and Remove 'USB selective suspend setting' in Power Options in Windows
Many thanks and credits to Paul Black (Gold Member, 4 star-Guru, VIP Member ! View Profile: Paul Black - Windows 10 Help Forums)
Code:
@echo off
:: ##########################################################################################################
:: # Title : Turn On Or Off USB Selective Suspend #
:: # Created By: Paul Black at TenForums.com/members/paul-black.html #
:: # Created In: November 2020 #
:: # Modified : Berbigou #
:: # : February 2022 #
:: # Tutorial : https://www.tenforums.com/tutorials/73187-turn-off-usb-selective-suspend-windows-10-a.html #
:: ##########################################################################################################
title Turn On Or Off USB Selective Suspend - Written by Paul Black & Berbigou.
mode con: cols=80 lines=25 & color 17
set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs") && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /b)
%windir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || ( echo. & echo ERROR: This Batch file MUST be run in an ELEVATED cmd prompt [ Administrator ] & echo. & echo Right-click the Batch file and click ^<Run as administrator^>. & echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & goto :Exit )
:Options
echo. & echo ==============================================================================
echo Turn On Or Off USB Selective Suspend, Remove or Show 'USB selective suspend'
echo ('USB selective suspend' appears in Power Options, see above)
echo (cf https://www.tenforums.com/tutorials/
echo 100643-remove-usb-selective-suspend-setting-power-options-windows.html)
echo ==============================================================================
echo. & echo Options:
echo. & echo [0] EXIT this Program.
echo. & echo [1] On Battery - Enabled [ Default ].
echo [2] On Battery - Disabled.
echo. & echo [3] Plugged In - Enabled [ Default ].
echo [4] Plugged In - Disabled.
echo. & echo [5] 'USB selective suspend' - Enabled.
echo [6] 'USB selective suspend' - Disabled [ Default in W10 Family Edition ].
echo. & echo ==============================================================================
echo.
CHOICE /N /C 0123456 /M ">Enter an Option:"
if %errorlevel%==7 goto Option_Dis
if %errorlevel%==6 goto Option_Ena
if %errorlevel%==5 goto Plugged_Dis
if %errorlevel%==4 goto Plugged_Ena
if %errorlevel%==3 goto Battery_Dis
if %errorlevel%==2 goto Battery_Ena
if %errorlevel%==1 goto Exit
goto :Options
:Battery_Ena
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 1
echo. Battery Enabled
goto :Complete
:Battery_Dis
powercfg /SETDCVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
echo. Battery Disabled
goto :Complete
:Plugged_Ena
powercfg /SETACVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 1
echo. Plugged Enabled
goto :Complete
:Plugged_Dis
powercfg /SETACVALUEINDEX SCHEME_CURRENT 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 0
echo. Plugged Disabled
goto :Complete
:Option_Ena
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\2a737441-1930-4402-8d77-b2bebba308a3\48e6b7a6-50f5-4782-a5d4-53bb8f07e226 /v Attributes /t REG_DWORD /d 2 /f
echo. Option Enabled
goto :Complete
:Option_Dis
powercfg -attributes 2a737441-1930-4402-8d77-b2bebba308a3 48e6b7a6-50f5-4782-a5d4-53bb8f07e226 +ATTRIB_HIDE
echo. Option Disabled
:Complete
echo. & echo Processing COMPLETE.
echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
:Exit
Berbigou, hope that helps