A parte complicada de verificar um valor de registro chamado *
(na verdade, um curinga de significado all ):
- consulta somente valores nomeados com um caractere usando
?
curinga, ou seja, no máximo um caractere e - restringir o resultado ao valor denominado
*
usandofindstr
utility ;- na verdade,
reg query "%_TestKey%" /v ? | findstr /I /C:" * REG_"
poderia ser suficiente.
- na verdade,
O seguinte trecho de código de arquivo em lote mostra que não há problema em adicionar, remover ou alterar um valor chamado *
.
O código é comentado usando <NUL set /P =::: …
truque ie echo ::: …
sem final CR LF para mostrar comentários na saída com um mínimo de linhas vazias.
@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_"
Saída :
==> 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