Reputation: 3384
Im using command line task in azure devops to install windows service.
First i need to check if service is already installed or not before going to uninstall it.
i use SC QUERY to check service exists or not
my full script as follows
@echo off
SC \\myserver QUERY servicename > NUL
IF ERRORLEVEL 1060 GOTO MISSING
ECHO SERVICE FOUND UNINSTALLING!
SC \\myserver STOP servicename
SC \\myserver DELETE servicename
GOTO END
:MISSING
ECHO COULD NOT FIND SERVICE!
GOTO END
:END
this works fine in local environment , but when task runs it fails with following error.
##[error]Cmd.exe exited with code '1060'.
is anyone has a solution for this?
Upvotes: 0
Views: 920
Reputation: 31
The reason for this is because the error still exists as DevOps exists the script. If you want to catch the specific error code you could exit with zero.
@echo off
SC \\myserver QUERY servicename > NUL
IF ERRORLEVEL 1060 GOTO MISSING
ECHO SERVICE FOUND UNINSTALLING!
SC \\myserver STOP servicename
SC \\myserver DELETE servicename
GOTO END
:MISSING
ECHO COULD NOT FIND SERVICE!
EXIT 0
:END
Upvotes: 2