Errorlevels

M

Mr. Novice

On my Win2k Pro workstation, the command listed below will
return an errorlevel of "1", which is correct because the
service is installed. On my co-workers Win2k Pro
workstation the command returns an errorlevel of "0"
despite the fact that the find statement does not
find "does not exist". It's seems that his machine is
pulling the errorlevel of the sc command, not the find
command, but mine is getting the errorleve value from the
find command. Can anyone explain this? Both machines are
using the same company image so there are no differences
in service pack levels or hot fixes.

sc \\server query "service" | find "does not exist"

Chad
 
M

Marty List

Mr. Novice said:
On my Win2k Pro workstation, the command listed below will
return an errorlevel of "1", which is correct because the
service is installed. On my co-workers Win2k Pro
workstation the command returns an errorlevel of "0"
despite the fact that the find statement does not
find "does not exist". It's seems that his machine is
pulling the errorlevel of the sc command, not the find
command, but mine is getting the errorleve value from the
find command. Can anyone explain this? Both machines are
using the same company image so there are no differences
in service pack levels or hot fixes.

sc \\server query "service" | find "does not exist"

Chad

You should also paste the code that is checking the errorlevel.

It sounds like you need something like this:

SetLocal
Set SERVER=server
Set SVC=service
Sc.exe \\%SERVER% query "%SVC%"|Find.exe "does not exist"
If %ERRORLEVEL% EQU 0 (
Echo %SERVER% is online and the %SVC% service does not exist.
) Else (
Echo Either the %SVC% service already exists, or %SERVER% is offline,
Echo or the SCM is hung, or you don't have rights, or ???
)

But as you can see this doesn't give you exactly what went wrong. The
errorlevels returned by SC.EXe are not very impressive. You should explain
exactly what you are trying to check for, and what you want to do after the
check. There's probably a more error-proof way of doing this.
 
M

Mr. Novice

-----Original Message-----



You should also paste the code that is checking the errorlevel.

It sounds like you need something like this:

SetLocal
Set SERVER=server
Set SVC=service
Sc.exe \\%SERVER% query "%SVC%"|Find.exe "does not exist"
If %ERRORLEVEL% EQU 0 (
Echo %SERVER% is online and the %SVC% service does not exist.
) Else (
Echo Either the %SVC% service already exists, or % SERVER% is offline,
Echo or the SCM is hung, or you don't have rights, or ???
)

But as you can see this doesn't give you exactly what went wrong. The
errorlevels returned by SC.EXe are not very impressive. You should explain
exactly what you are trying to check for, and what you want to do after the
check. There's probably a more error-proof way of doing this.



.

Hi Marty. Thanks for the response. I didn't put the code
that checks the errorlevel because it was simply echo %
errorlevel%. I figured that was understood. The code you
provided is very similar to what I'm using in my script.
When the problem came up I removed all the fluff and tried
manually running core statement which is what I pasted in
the first post and then echoed the errorlevel. The problem
persisted even without all the fluff and that's when I
posted the question. The intent of the script is to cycle
a service on a server. The script asks what server, sets
the input as a variable, pings the target server to make
sure it's online, and then checks to see if the service
exist on the target server before trying to restart it.
The part that checks to see if the service exist on the
target server is where the problem is.

Thanks again for the response. If you have any other
ideas, I'd love to hear them. I'll try to be more specific
on future postings.

Chad
 

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