如何验证regedit结果?
How to verify regedit result?
如何验证 regedit 查询请求的值?
REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
使用find
or findstr
过滤需要的行,然后使用for /f
读取输出
for /f "tokens=3" %%v in ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
如果您只是想在 1
和 0
之间切换值,这些内容可能对您有用,(只要您有合适的access/modify 值数据的权限).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
在万维网上可以找到很多关于如何更改 Windows 8 和更高 Windows 版本的快速启动设置的文章。
这里还有一个批处理文件解决方案,必须运行作为管理员:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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%\System32\reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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
此批处理文件设计用于在 Windows XP / Windows Server 2003 和所有更新的 Windows 版本上执行。如果 Windows 由于不支持快速启动而没有双字注册表值 HiberBootEnabled
,则什么也不做。如果在没有本地管理员提升权限的情况下执行批处理文件,它也不会执行任何操作,而本地管理员需要对 HKEY_LOCAL_MACHINE
注册表配置单元进行写入访问。
这也是一个优化版本,使用简单而伟大的方法从 1
中减去双字的当前值以切换它,如 Compo 在他的回答中发布的那样。
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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%\System32\reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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
根据 LotPings 的建议,最好是第五行:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
此行将 HiberBootEnabled
设置为 0
,即使当前值大于 1
。
要了解使用的命令及其工作原理,请打开命令提示符 window,在其中执行以下命令,并仔细阅读为每个命令显示的所有帮助页面。
call /?
.. 解释 %~nx0
(带扩展名的批处理文件的名称)
echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?
如何验证 regedit 查询请求的值?
REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled"
IF result == 1 goto turoff
IF result == 0 goto turnon
使用find
or findstr
过滤需要的行,然后使用for /f
读取输出
for /f "tokens=3" %%v in ('REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" ^| find "HiberbootEnabled"') do set result=%%v
if "%result%" == "0x1" (
turnoff
) else (
turnon
)
如果您只是想在 1
和 0
之间切换值,这些内容可能对您有用,(只要您有合适的access/modify 值数据的权限).
@Echo Off
Set "DWord="
For /F "Tokens=3" %%A In ('
Reg Query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" 2^>Nul
') Do 2>Nul Set /A DWord=1-%%A
If Defined DWord Reg Add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul
在万维网上可以找到很多关于如何更改 Windows 8 和更高 Windows 版本的快速启动设置的文章。
这里还有一个批处理文件解决方案,必须运行作为管理员:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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%\System32\reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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
此批处理文件设计用于在 Windows XP / Windows Server 2003 和所有更新的 Windows 版本上执行。如果 Windows 由于不支持快速启动而没有双字注册表值 HiberBootEnabled
,则什么也不做。如果在没有本地管理员提升权限的情况下执行批处理文件,它也不会执行任何操作,而本地管理员需要对 HKEY_LOCAL_MACHINE
注册表配置单元进行写入访问。
这也是一个优化版本,使用简单而伟大的方法从 1
中减去双字的当前值以切换它,如 Compo 在他的回答中发布的那样。
@echo off
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1-3" %%A in ('%SystemRoot%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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%\System32\reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /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
根据 LotPings 的建议,最好是第五行:
if /I "%%A" == "HiberBootEnabled" set /A "HiberBootEnabled=!%%C" & goto ToggleValue
此行将 HiberBootEnabled
设置为 0
,即使当前值大于 1
。
要了解使用的命令及其工作原理,请打开命令提示符 window,在其中执行以下命令,并仔细阅读为每个命令显示的所有帮助页面。
call /?
.. 解释%~nx0
(带扩展名的批处理文件的名称)echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /?
reg add /?
reg query /?
rem /?
set /?
setlocal /?