Fyodor Koryazhkin
10-02-2005, 09:23 AM
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
Michael Bednarek
10-02-2005, 02:11 PM
On Sun, 02 Oct 2005 01:23:32 -0700, Fyodor Koryazhkin
<fyodork@smarteam.com> wrote in
microsoft.public.win2000.cmdprompt.admin:
>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.".
--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Mark V
10-02-2005, 02:53 PM
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.