在命令提示符下添加,删除和testing是否存在registry值*

我正在尝试从命令提示符检查并更新registry中的networking区域映射。 我需要检查名为*的值。 例如,在HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ ZoneMap \ Domains \ cmich.local下 ,registry编辑器显示以下内容:

* REG_DWORD 0x00000001 (1)

要在命令脚本(* .cmd)中检查此值,我一直在尝试使用REG QUERY命令。 当我试图通过传递*作为匹配的值时,REG QUERY命令将星号视为通配符,只要键存在就返回一个匹配。

 reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\example.com" /v "*" /reg:64 

我已经尝试了许多组合的转义字符(即使那些我相当肯定不会工作),包括所有以下引号和引号: *\*^*`*`*` !* 。 这些都没有工作。

我还需要添加和删除名称*值,大概是与REG ADD和REG DELETE。

如何在命令提示符处添加,删除和testing是否存在具有名称*的registry值?

检查名为*的registry值的棘手部分(实际上是所有的通配符):

  • 查询只使用一个字符的命名值? 通配符,即至多一个字符 ,和
  • 使用findstr实用程序将结果缩小到名为*的值;
    • 其实reg query "%_TestKey%" /v ? | findstr /I /C:" * REG_" reg query "%_TestKey%" /v ? | findstr /I /C:" * REG_" reg query "%_TestKey%" /v ? | findstr /I /C:" * REG_"就足够了。

以下batch file代码片断显示添加,删除或更改名为*的值没有问题。

代码使用<NUL set /P =::: … trick即echo ::: …注释,没有结尾的CR LF ,以最less的空行显示输出中的注释。

 @ECHO ON @SETLOCAL EnableExtensions DisableDelayedExpansion @<NUL set /P =::: define a registry key set "_TestKey=HKEY_CURRENT_USER\Software\Test Key" @<NUL set /P =::: check all one-character named values reg query "%_TestKey%" /v ? @<NUL set /P =::: narrow above result to the value named * using findstr utility reg query "%_TestKey%" /v ? | findstr /I /C:"%_TestKey%" /C:" * REG_" @<NUL set /P =::: delete the value named * reg delete "%_TestKey%" /v * /f @<NUL set /P =::: add the value named * reg add "%_TestKey%" /v * /t REG_DWORD /d 4 /f @<NUL set /P =::: check the value named * reg query "%_TestKey%" /v ? | findstr /I /C:"%_TestKey%" /C:" * REG_" @<NUL set /P =::: change the value named * reg add "%_TestKey%" /v * /t REG_DWORD /d 1 /f @<NUL set /P =::: check the value named * reg query "%_TestKey%" /v ? | findstr /I /C:"%_TestKey%" /C:" * REG_" 

输出

 ==> D:\bat\SF\a867740.bat ::: define a registry key ==> set "_TestKey=HKEY_CURRENT_USER\Software\Test Key" ::: check all one-character named values ==> reg query "HKEY_CURRENT_USER\Software\Test Key" /v ? HKEY_CURRENT_USER\Software\Test Key a REG_SZ Latin Small Letter A . REG_SZ Full Stop ? REG_SZ Question Mark * REG_DWORD 0x1 End of search: 4 match(es) found. ::: narrow above result to the value named * using findstr utility ==> reg query "HKEY_CURRENT_USER\Software\Test Key" /v ? | findstr /I /C:"HKEY_CURRENT_USER\Software\Test Key" /C:" * REG_" HKEY_CURRENT_USER\Software\Test Key * REG_DWORD 0x1 ::: delete the value named * ==> reg delete "HKEY_CURRENT_USER\Software\Test Key" /v * /f The operation completed successfully. ::: add the value named * ==> reg add "HKEY_CURRENT_USER\Software\Test Key" /v * /t REG_DWORD /d 4 /f The operation completed successfully. ::: check the value named * ==> reg query "HKEY_CURRENT_USER\Software\Test Key" /v ? | findstr /I /C:"HKEY_CURRENT_USER\Software\Test Key" /C:" * REG_" HKEY_CURRENT_USER\Software\Test Key * REG_DWORD 0x4 ::: change the value named * ==> reg add "HKEY_CURRENT_USER\Software\Test Key" /v * /t REG_DWORD /d 1 /f The operation completed successfully. ::: check the value named * ==> reg query "HKEY_CURRENT_USER\Software\Test Key" /v ? | findstr /I /C:"HKEY_CURRENT_USER\Software\Test Key" /C:" * REG_" HKEY_CURRENT_USER\Software\Test Key * REG_DWORD 0x1