How to verify regedit result?
up vote
0
down vote
favorite
How do I verify the value of a regedit query request?
REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
batch-file regedit
add a comment |
up vote
0
down vote
favorite
How do I verify the value of a regedit query request?
REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
batch-file regedit
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How do I verify the value of a regedit query request?
REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
batch-file regedit
How do I verify the value of a regedit query request?
REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
batch-file regedit
batch-file regedit
edited Nov 11 at 12:36
phuclv
14.3k850209
14.3k850209
asked Nov 10 at 21:57
Geemo
34
34
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
If you're just wanting to toggle the value betwen 1
and 0
, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
1
To toggle between 0 and 1 you could also useSet /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)
– LotPings
Nov 11 at 12:43
add a comment |
up vote
0
down vote
Use find
or findstr
to filter the line needed, and then use for /f
to read the output
for /f "tokens=3" %%v in ('REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
add a comment |
up vote
0
down vote
There can be found lots of articles in world wide web on how to change the fast startup setting of Windows 8 and later Windows versions.
Here is one more commented batch file solution which must be run as administrator:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=%%C" & goto EvaluateValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:EvaluateValue
rem Toggle the hibernate boot setting.
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=1") else set "HiberBootEnabled=0"
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle the
echo fast startup (hibernate boot) setting in Windows registry.
:EndBatch
echo/
pause
endlocal
This batch file is designed for being executed on Windows XP / Windows Server 2003 and all newer Windows versions. There is nothing done if Windows does not already have the double word registry value HiberBootEnabled
because of not supporting fast startup. It also does nothing if the batch file is executed without elevated privileges of a local administrator required for write access to HKEY_LOCAL_MACHINE
registry hive.
Here is also an optimized version using the simple and great method to subtract from 1
the current value of the double word to toggle it as posted by Compo in his answer.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=1-%%C" & goto ToggleValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:ToggleValue
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle
echo the hibernate boot setting in Windows registry.
:EndBatch
echo/
pause
endlocal
And even better would be as fifth line according to suggestion by LotPings:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
This line sets HiberBootEnabled
to 0
even if the current value is greater 1
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
.. explains%~nx0
(name of batch file with extension)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243807%2fhow-to-verify-regedit-result%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
If you're just wanting to toggle the value betwen 1
and 0
, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
1
To toggle between 0 and 1 you could also useSet /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)
– LotPings
Nov 11 at 12:43
add a comment |
up vote
3
down vote
accepted
If you're just wanting to toggle the value betwen 1
and 0
, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
1
To toggle between 0 and 1 you could also useSet /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)
– LotPings
Nov 11 at 12:43
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
If you're just wanting to toggle the value betwen 1
and 0
, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
If you're just wanting to toggle the value betwen 1
and 0
, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
answered Nov 11 at 11:42
Compo
15.3k3926
15.3k3926
1
To toggle between 0 and 1 you could also useSet /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)
– LotPings
Nov 11 at 12:43
add a comment |
1
To toggle between 0 and 1 you could also useSet /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)
– LotPings
Nov 11 at 12:43
1
1
To toggle between 0 and 1 you could also use
Set /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)– LotPings
Nov 11 at 12:43
To toggle between 0 and 1 you could also use
Set /A "DWord=!%%A"
both are less obvious than an if but IMO more elegant. (+1)– LotPings
Nov 11 at 12:43
add a comment |
up vote
0
down vote
Use find
or findstr
to filter the line needed, and then use for /f
to read the output
for /f "tokens=3" %%v in ('REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
add a comment |
up vote
0
down vote
Use find
or findstr
to filter the line needed, and then use for /f
to read the output
for /f "tokens=3" %%v in ('REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
add a comment |
up vote
0
down vote
up vote
0
down vote
Use find
or findstr
to filter the line needed, and then use for /f
to read the output
for /f "tokens=3" %%v in ('REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
Use find
or findstr
to filter the line needed, and then use for /f
to read the output
for /f "tokens=3" %%v in ('REG QUERY "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
answered Nov 11 at 3:39
phuclv
14.3k850209
14.3k850209
add a comment |
add a comment |
up vote
0
down vote
There can be found lots of articles in world wide web on how to change the fast startup setting of Windows 8 and later Windows versions.
Here is one more commented batch file solution which must be run as administrator:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=%%C" & goto EvaluateValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:EvaluateValue
rem Toggle the hibernate boot setting.
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=1") else set "HiberBootEnabled=0"
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle the
echo fast startup (hibernate boot) setting in Windows registry.
:EndBatch
echo/
pause
endlocal
This batch file is designed for being executed on Windows XP / Windows Server 2003 and all newer Windows versions. There is nothing done if Windows does not already have the double word registry value HiberBootEnabled
because of not supporting fast startup. It also does nothing if the batch file is executed without elevated privileges of a local administrator required for write access to HKEY_LOCAL_MACHINE
registry hive.
Here is also an optimized version using the simple and great method to subtract from 1
the current value of the double word to toggle it as posted by Compo in his answer.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=1-%%C" & goto ToggleValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:ToggleValue
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle
echo the hibernate boot setting in Windows registry.
:EndBatch
echo/
pause
endlocal
And even better would be as fifth line according to suggestion by LotPings:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
This line sets HiberBootEnabled
to 0
even if the current value is greater 1
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
.. explains%~nx0
(name of batch file with extension)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
add a comment |
up vote
0
down vote
There can be found lots of articles in world wide web on how to change the fast startup setting of Windows 8 and later Windows versions.
Here is one more commented batch file solution which must be run as administrator:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=%%C" & goto EvaluateValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:EvaluateValue
rem Toggle the hibernate boot setting.
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=1") else set "HiberBootEnabled=0"
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle the
echo fast startup (hibernate boot) setting in Windows registry.
:EndBatch
echo/
pause
endlocal
This batch file is designed for being executed on Windows XP / Windows Server 2003 and all newer Windows versions. There is nothing done if Windows does not already have the double word registry value HiberBootEnabled
because of not supporting fast startup. It also does nothing if the batch file is executed without elevated privileges of a local administrator required for write access to HKEY_LOCAL_MACHINE
registry hive.
Here is also an optimized version using the simple and great method to subtract from 1
the current value of the double word to toggle it as posted by Compo in his answer.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=1-%%C" & goto ToggleValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:ToggleValue
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle
echo the hibernate boot setting in Windows registry.
:EndBatch
echo/
pause
endlocal
And even better would be as fifth line according to suggestion by LotPings:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
This line sets HiberBootEnabled
to 0
even if the current value is greater 1
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
.. explains%~nx0
(name of batch file with extension)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
add a comment |
up vote
0
down vote
up vote
0
down vote
There can be found lots of articles in world wide web on how to change the fast startup setting of Windows 8 and later Windows versions.
Here is one more commented batch file solution which must be run as administrator:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=%%C" & goto EvaluateValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:EvaluateValue
rem Toggle the hibernate boot setting.
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=1") else set "HiberBootEnabled=0"
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle the
echo fast startup (hibernate boot) setting in Windows registry.
:EndBatch
echo/
pause
endlocal
This batch file is designed for being executed on Windows XP / Windows Server 2003 and all newer Windows versions. There is nothing done if Windows does not already have the double word registry value HiberBootEnabled
because of not supporting fast startup. It also does nothing if the batch file is executed without elevated privileges of a local administrator required for write access to HKEY_LOCAL_MACHINE
registry hive.
Here is also an optimized version using the simple and great method to subtract from 1
the current value of the double word to toggle it as posted by Compo in his answer.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=1-%%C" & goto ToggleValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:ToggleValue
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle
echo the hibernate boot setting in Windows registry.
:EndBatch
echo/
pause
endlocal
And even better would be as fifth line according to suggestion by LotPings:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
This line sets HiberBootEnabled
to 0
even if the current value is greater 1
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
.. explains%~nx0
(name of batch file with extension)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
There can be found lots of articles in world wide web on how to change the fast startup setting of Windows 8 and later Windows versions.
Here is one more commented batch file solution which must be run as administrator:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=%%C" & goto EvaluateValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:EvaluateValue
rem Toggle the hibernate boot setting.
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=1") else set "HiberBootEnabled=0"
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle the
echo fast startup (hibernate boot) setting in Windows registry.
:EndBatch
echo/
pause
endlocal
This batch file is designed for being executed on Windows XP / Windows Server 2003 and all newer Windows versions. There is nothing done if Windows does not already have the double word registry value HiberBootEnabled
because of not supporting fast startup. It also does nothing if the batch file is executed without elevated privileges of a local administrator required for write access to HKEY_LOCAL_MACHINE
registry hive.
Here is also an optimized version using the simple and great method to subtract from 1
the current value of the double word to toggle it as posted by Compo in his answer.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%System32reg.exe query "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /v "HiberBootEnabled" 2^>nul') do (
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=1-%%C" & goto ToggleValue
)
for /F "delims=" %%I in ('ver') do set "WindowsVersion=%%I"
echo Fast startup (hibernate boot) setting not found in Windows registry.
echo/
echo %WindowsVersion% does not support fast startup.
goto EndBatch
:ToggleValue
rem Change the hibernate boot setting in registry if batch file
rem is executed with elevated permissions of a local administrator.
%SystemRoot%System32reg.exe add "HKLMSYSTEMCurrentControlSetControlSession ManagerPower" /f /v "HiberBootEnabled" /t REG_DWORD /d %HiberBootEnabled% >nul
if errorlevel 1 goto ErrorAddValue
if %HiberBootEnabled% == 0 (set "HiberBootEnabled=OFF") else set "HiberBootEnabled=ON"
echo Fast startup (hibernate boot) setting toggled %HiberBootEnabled%.
goto EndBatch
:ErrorAddValue
echo/
echo %~nx0 must be run as administrator to toggle
echo the hibernate boot setting in Windows registry.
:EndBatch
echo/
pause
endlocal
And even better would be as fifth line according to suggestion by LotPings:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
This line sets HiberBootEnabled
to 0
even if the current value is greater 1
.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
.. explains%~nx0
(name of batch file with extension)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
edited Nov 11 at 13:04
answered Nov 11 at 12:40
Mofi
27.3k83776
27.3k83776
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243807%2fhow-to-verify-regedit-result%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown