Link to home
Start Free TrialLog in
Avatar of kwatt562
kwatt562Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Return code 0 on error

Hi running a bat script to delete some registry keys
I don't want the script to fail if it cant find a registry value

reg delete HKCR\Installer\Products\B074548141BECBA438B53EC696D30CD8 /f
I need it to return error value of 0 if a key isn't  found, can someone assist?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and if it is not the last line in the batch you can simply use labels, goto's and if statements; e.g. -
reg delete HKCR\Installer\Products\B074548141BECBA438B53EC696D30CD8 /f
if %ERRORLEVEL% EQU 1 goto _Section1
:: Do some more stuff because the entry was removed.
echo Doing more stuff, yay...
:_Section1
reg delete HKCR\Installer\Products\<NEXTProductID> /f
if %ERRORLEVEL% EQU 1 goto _Section2
:: Do some more stuff because the entry was removed.
echo Doing more stuff, yay...
:_Section2
...
...
...
:_eof
exit /b 0

Open in new window

-saige-
There are only a few situations where you should use labels. In general - no!