icek
icek

Reputation: 69

Disabling allowance of Windows to save power for USB devices via batch loop

Dears, I was struggling on how to disable allowance of Windows to save power for USB Readers and finally with RegShot I managed to find registry inputs which are responsible for those settings so I managed to create two reg queries which are scanning Computer:

REG QUERY HKLM /v SelectiveSuspendFeatureOn /s
REG QUERY HKLM /v EnableSelectiveSuspend /s

Example output:

C:\Users\asd\Desktop>REG QUERY HKLM /v SelectiveSuspendFeatureOn /s

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\GemCCID SelectiveSuspendFeatureOn REG_DWORD 0x1

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\GemCCID SelectiveSuspendFeatureOn REG_DWORD 0x1

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\GemCCID SelectiveSuspendFeatureOn REG_DWORD 0x1

End of search: 3 match(es) found.

C:\Users\asd\Desktop>REG QUERY HKLM /v EnableSelectiveSuspend /s

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\IUSB3\ROOT_HUB30\4&22fe6fd&0\Device Parameters EnableSelectiveSuspend REG_DWORD 0x1

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Enum\IUSB3\ROOT_HUB30\4&22fe6fd&0\Device Parameters EnableSelectiveSuspend REG_DWORD 0x1

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IUSB3\ROOT_HUB30\4&22fe6fd&0\De vice Parameters EnableSelectiveSuspend REG_DWORD 0x1

End of search: 3 match(es) found.

So now after I'm able to scan those places and acquire registry paths I want to set them every each of them to 0 so I managed to find and use this .bat :

@echo off
cls
:startreg
cls
set regq= REG QUERY HKLM /v SelectiveSuspendFeatureOn /s %curuser%
for /f "tokens=* delims=~" %%A IN ('%regq% ^| findstr /i "HKEY_LOCAL_MACHINE"') DO set regkey=%%A

Reg add %regkey% /v SelectiveSuspendFeatureOn /t REG_DWORD /d 0 /f
rem Reg add %regkey% /v EnableSelectiveSuspend /t REG_DWORD /d 0 /f

pause
exit

Now this is where I stuck, I got two requests/questions related to .bat itself:

  1. Each listed item from REQ QUERY should be set to 0 with REG ADD command - so I believe this should be looped somehow? Out put commands must be generated to .reg file (example below)
  2. How to add second option for EnableSelectiveSuspend, is there a way to double-loop this?

@@ EDIT.1 @@

Turned out that some Registry Keys cannot be changed via .bat (path cannot be read) so .reg file should be generated instead:

example of correct .reg file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\GemCCID] "SelectiveSuspendFeatureOn"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet004\services\GemCCID] "SelectiveSuspendFeatureOn"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\GemCCID] "SelectiveSuspendFeatureOn"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet004\Enum\IUSB3\ROOT_HUB30\4&32305751&0\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet004\Enum\USB\VID_0424&PID_2512\5&36b4634f&0&3\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet004\Enum\USB\VID_0424&PID_2514\6&234568e7&0&1\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IUSB3\ROOT_HUB30\4&32305751&0\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0424&PID_2512\5&36b4634f&0&3\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0424&PID_2514\6&234568e7&0&1\Device Parameters] "EnableSelectiveSuspend"=dword:00000000

Looking forward for your answers.

Patryk

@@ EDIT 2 @@

I managed to create logic I needed:

@echo off

cls
:startreg
cls
echo Scanning computer in order to apply Power Managment adjustments for USB readers
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo Windows Registry Editor Version 5.00 > %1/scanned.reg
echo. >> %1/scanned.reg
set regq= REG QUERY HKLM /v SelectiveSuspendFeatureOn /s %curuser%
for /f "tokens=* delims=\\n" %%A IN ('%regq% ^| findstr /i "HKEY_LOCAL_MACHINE"') DO echo [%%A] >> %1/scanned.reg & echo "SelectiveSuspendFeatureOn"=dword:00000000 >> %1/scanned.reg & echo.  >> %1/scanned.reg

set regq= REG QUERY HKLM /v EnableSelectiveSuspend /s %curuser%
for /f "tokens=* delims=\\n" %%A IN ('%regq% ^| findstr /i "HKEY_LOCAL_MACHINE"') DO echo [%%A] >> %1/scanned.reg & echo "EnableSelectiveSuspend"=dword:00000000 >> %1/scanned.reg & echo.  >> %1/scanned.reg

regedit.exe /S %1/scanned.reg

exit

So this one is scanning Windows registry, then saving those values as .reg key and ultimately running the .reg file to apply changes.

After register udpates - restart of system is needed.

This one has argument "path" added so you should run this .bat with argument for example "C:" or any other path.

Upvotes: 6

Views: 1149

Answers (1)

icek
icek

Reputation: 69

I managed to create logic I needed:

@echo off

cls
:startreg
cls
echo Scanning computer in order to apply Power Managment adjustments for USB readers
echo Windows Registry Editor Version 5.00 > %1/scanned.reg
echo. >> %1/scanned.reg
set regq= REG QUERY HKLM /v SelectiveSuspendFeatureOn /s %curuser%
for /f "tokens=* delims=\\n" %%A IN ('%regq% ^| findstr /i "HKEY_LOCAL_MACHINE"') DO echo [%%A] >> %1/scanned.reg & echo "SelectiveSuspendFeatureOn"=dword:00000000 >> %1/scanned.reg & echo.  >> %1/scanned.reg

set regq= REG QUERY HKLM /v EnableSelectiveSuspend /s %curuser%
for /f "tokens=* delims=\\n" %%A IN ('%regq% ^| findstr /i "HKEY_LOCAL_MACHINE"') DO echo [%%A] >> %1/scanned.reg & echo "EnableSelectiveSuspend"=dword:00000000 >> %1/scanned.reg & echo.  >> %1/scanned.reg

regedit.exe /S %1/scanned.reg

exit

So this one is scanning Windows registry, then saving those values as .reg key and ultimately running the .reg file to apply changes.

After register udpates - restart of system is needed.

This one has argument "path" added so you should run this .bat with argument for example "C:" or any other path.

Upvotes: 0

Related Questions