summary
概要
I need to be able to find the DWORD value of a registry key and set a variable to it to run an if statement against it.
我需要能够找到注册表项的DWORD值并为其设置一个变量以对其运行if语句。
how can i grab just the dword of a reg query so that i can work with it in the rest of my script?
我怎样才能抓住一个reg查询的双关语,以便我可以在其余的脚本中使用它?
reg query
reg查询
reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall
req query output
req查询输出
EnableFirewall REG_DWORD 0x1
what i need to grab
我需要抓住什么
0x1
为0x1
pseudo code
伪代码
query firewall reg value
regex out DWORD value and set to variable var1
if var1 == 0x1 then do blah
else do other blah
2 个解决方案
#1
9
try this:
尝试这个:
@echo off &setlocal
for /f "tokens=2*" %%a in ('reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall') do set "var=%%b"
if "%var%"=="0x1" (do this) else do that
#2
3
This should work for you:
这应该适合你:
for /f "tokens=3" %%x in ('reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall') do set FWSTATUS=%%x
If testing from the command line, change the %%x
to %x
instead.
如果从命令行进行测试,请将%% x更改为%x。
#1
9
try this:
尝试这个:
@echo off &setlocal
for /f "tokens=2*" %%a in ('reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall') do set "var=%%b"
if "%var%"=="0x1" (do this) else do that
#2
3
This should work for you:
这应该适合你:
for /f "tokens=3" %%x in ('reg query HKLM\System\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile /v EnableFirewall') do set FWSTATUS=%%x
If testing from the command line, change the %%x
to %x
instead.
如果从命令行进行测试,请将%% x更改为%x。