Delete subkeys in a registry key
Posted: 24 Jan 2023 12:05
I tried creating a .bat scrip to search the subkeys of one registry entry for a string anyplace in the subkey.
The registry key is below in a Set "Key="
There are 165 subkeys. One subkey example looks like:
If the subkey has the string that I have in a Set "Str=" below, I'd like to delete the subkey.
I don't understand enough about a for loop.
I don't understand enough about searching a subkey.
I took a stab at creating something that is currently not working:
I'm running this in Windows 10
Please give me a suggestion on how to fix the "For" loop.
The registry key is below in a Set "Key="
There are 165 subkeys. One subkey example looks like:
Code: Select all
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\UltraVNC\UltraVNC Viewer\UltraVNC Viewer (Listen Mode).lnk
C:\Program Files\uvnc bvba\UltraVNC\vncviewer.exe
-listen
I don't understand enough about a for loop.
I don't understand enough about searching a subkey.
I took a stab at creating something that is currently not working:
Code: Select all
@Echo On
Set "Key=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UFH\SHC"
Set "Str=uvnc bvba"
setlocal EnableExtensions DisableDelayedExpansion
for /F "usebackq delims=" %%I in ("%Str%") do (Echo reg delete "%Key%" /v "%%~I" /f 2>nul
if not errorlevel 1 echo Deleted "%%~I" from %Key%
)
endlocal
cmd /k
Please give me a suggestion on how to fix the "For" loop.