• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

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?
0
kwatt562
Asked:
kwatt562
  • 2
1 Solution
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
If that is the last command in the batch, just use

exit /b 0

as last statement to exit with a return value of 0.
0
 
it_saigeDeveloperCommented:
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-
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
There are only a few situations where you should use labels. In general - no!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now