I have a list of registry keys/values/entries that I would like to delete (basically the list in #3 below without the REG DELETE stuff). It works as is but I'd like to have the batch...
I. Write the listfile.txt itself if list.txt doesn't exist in %~dp0
set "ListFile=%TEMP%\ListFile.txt"
set "List=%~dp0list.txt"
if not exist "%List%" (
(
echo Some regisrtry key
echo Some registry value
echo Some registry subkey
echo No idea how it should all be written like
) >"%ListFile%"
)
II. Check the existence of each in the list with REG QUERY and have an ERRORLEVEL
If it exists..
- REG EXPORT it to its own valid .reg (that can be imported back in case something goes wrong).
for /f %%A in (%src%) do (
if not exist "%bkp%\%%A" md "%bkp%\%%A"
reg export "%%A" "%bkp%\%%A\key.reg"
I'm not sure if the above will work with specific values or all entries within a specified key.
compare the list and .reg
if it matches, run REG DELETE /f or REG DELETE /v /f or REG DELETE /va /f as appropriate.
REG DELETE "HKCU\Software\Google\Chrome" /f
REG DELETE "HKLM\Software\Google\Chrome" /f
REG DELETE "HKCU\Software\Policies\Google\Chrome" /f
REG DELETE "HKLM\Software\Policies\Google\Chrome" /f
REG DELETE "HKLM\Software\Policies\Google\Update" /f
REG DELETE "HKLM\Software\WOW6432Node\Google\Enrollment" /f
REG DELETE "HKLM\Software\WOW6432Node\Google\Update\ClientState\{430FD4D0-B729-4F61-AA34-91526481799D}" /v CloudManagementEnrollmentToken /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Policies" /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKCU\Software\Microsoft\WindowsSelfHost" /f
REG DELETE "HKLM\Software\Microsoft\WindowsSelfHost" /f
REG DELETE "HKLM\Software\Microsoft\Policies" /f
REG DELETE "HKCU\Software\Policies" /f
REG DELETE "HKLM\Software\Policies" /f
REG DELETE "HKLM\Software\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /f
REG DELETE "HKLM\Software\Policies\Microsoft\Edge" /va /f
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" /f
- ECHO to cmd and %~dp0output.log that the keys/values/entries had been processed and deleted
If it doesn't exist..
- ECHO to cmd and %~dp0output.log that it doesn't exist
"HKCU\Software\Google\Chrome" key does not exist
No entries can be found in "HKLM\Software\Policies\Microsoft\Edge"
Value DisableAntiSpyware cannot be found in "HKLM\Software\Policies\Microsoft\Windows Defender"
III. Delete the list that was created by the batch but not if it was already present.
IF EXIST "%ListFile%" ( DEL "%ListFile%" ) ELSE ( goto :eof )
I attempted to modify the snippets I found but do not understand yet how for loops work at all and also in a way that I will only have one list and the for loop will adapt in case it is a key, is a value (/v) and/or only requires to process all entries within the specified key (/va)
The current script below works so far but is misssing all the points above. Any help to add those is appreciated.
REG DELETE "HKCU\Software\Google\Chrome" /f
REG DELETE "HKLM\Software\Google\Chrome" /f
REG DELETE "HKCU\Software\Policies\Google\Chrome" /f
REG DELETE "HKLM\Software\Policies\Google\Chrome" /f
REG DELETE "HKLM\Software\Policies\Google\Update" /f
REG DELETE "HKLM\Software\WOW6432Node\Google\Enrollment" /f
REG DELETE "HKLM\Software\WOW6432Node\Google\Update\ClientState\{430FD4D0-B729-4F61-AA34-91526481799D}" /v CloudManagementEnrollmentToken /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Policies" /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies" /f
REG DELETE "HKCU\Software\Microsoft\WindowsSelfHost" /f
REG DELETE "HKLM\Software\Microsoft\WindowsSelfHost" /f
REG DELETE "HKLM\Software\Microsoft\Policies" /f
REG DELETE "HKCU\Software\Policies" /f
REG DELETE "HKLM\Software\Policies" /f
REG DELETE "HKLM\Software\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /f
REG DELETE "HKLM\Software\Policies\Microsoft\Edge" /va /f
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" /f
REG DELETE "HKLM\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\WindowsStore\WindowsUpdate" /f
@RD /S /Q "%ProgramFiles(x86)%\Google\Policies"
@RD /S /Q "%WinDir%\System32\GroupPolicy"
@RD /S /Q "%WinDir%\System32\GroupPolicyUsers"
ECHO.
gpupdate /force
ECHO.
ECHO Complete. Will shutdown..
pause>nul
shutdown.exe /r /t 00
EXIT /B 0