1

I am trying to check and update the network zone mapping in the registry from the Command Prompt. I need to check for the value named *. For example, under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\cmich.local, Registry Editor shows the following:

* REG_DWORD 0x00000001 (1)

To check this value in a command script (*.cmd), I have been attempting to use the REG QUERY command. When I attempt to do so by passing * as the value to match, the REG QUERY command treats the asterisk as a wildcard and returns a match as long as the key exists.

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

I've tried numerous combinations of escape characters (even those that I was pretty sure wouldn't work), including all of the following with and without quotation marks: *, \*, ^*, `*, `*`, !*. None of these worked.

I also need to add and remove values with the name *, presumably with REG ADD and REG DELETE.

How do I add, remove, and test for the existence of a registry value with the name * at the Command Prompt?

3
  • Is Powershell an option? – Ryan Bolger Aug 9 '17 at 16:05
  • I ran into the same trouble using PowerShell's Get-Item cmdlet on the registry key and trying to extract the properties. I can't find a syntax that makes the cmdlet use * as the name of the registry value rather than as a wildcard. – Jay Michaud Aug 9 '17 at 17:22
  • Did you try in Powershell with -LiteralPath ? Get-ChildItem -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell" and possibly piping the proper value to Remove-Item? – LotPings Aug 9 '17 at 18:28
1

The tricky part of checking a registry value named * (actually a wildcard of meaning all):

  • query only one-character named values using ? wildcard i.e. at most one character, and
  • narrow the result to the value named * using findstr utility;
    • in fact, reg query "%_TestKey%" /v ? | findstr /I /C:" * REG_" could suffice.

The following batch-file code snippet shows that there is no issue with adding, removing or changing a value named *.

The code is commented using <NUL set /P =::: … trick i.e. echo ::: … with no ending CRLF to show comments in output with minimum of empty lines.

@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_"

Output:

==> 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.