Errorlevel of net stop

  • Thread starter Fyodor Koryazhkin
  • Start date
F

Fyodor Koryazhkin

Hi,
How can I verify the exit code of net start or net stop commands?

If I use net stop in a batch file and the service does not exist or already
stoped I want to stop executing the rest of the batch file and show the appropriate
message to the user.
Executing this command alone shows system error 1060 - "The specified service
does not exist as an installed service." however the errorlevel after executing
is 0.

So how to verify the real exit code?

Thank you.
Fyodor Koryazhkin
 
M

Michael Bednarek

How can I verify the exit code of net start or net stop commands?

If I use net stop in a batch file and the service does not exist or already
stoped I want to stop executing the rest of the batch file and show the appropriate
message to the user.
Executing this command alone shows system error 1060 - "The specified service
does not exist as an installed service." however the errorlevel after executing
is 0.

So how to verify the real exit code?

Here (NT5.1) NET STOP for a non-existing or already stopped service
results in %ERRORLEVEL%==2 - are you sure yours is different?

If it is, you could parse the output of NET STOP for success, e.g. for
the string "was stopped successfully.".
 
M

Mark V

In microsoft.public.win2000.cmdprompt.admin Fyodor Koryazhkin
wrote:
Hi,
How can I verify the exit code of net start or net stop
commands?

If I use net stop in a batch file and the service does not exist
or already stoped I want to stop executing the rest of the batch
file and show the appropriate message to the user.
Executing this command alone shows system error 1060 - "The
specified service does not exist as an installed service."
however the errorlevel after executing is 0.

So how to verify the real exit code?

I'm not certain, but NET.EXE may return (and set errorlevel) after
passing the command to the SCM and may be therefore irrelevent. In
my opinion you would do better using
sc.exe (Resource Kit)
psservice.exe (Sysinternals)
if possible in your batch file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top