Friday, February 23, 2007

Errorlevels and Windows XP

I was recently playing with a script to do some basica automated failover depending on whether a certain service was running or not and came accross an interesting fact that Windows XP and I think any newer Windows OS younger than Windows 98 doesn't see Errorlevel =0 as success, instead the successful errorlevel is 255.

For instance - to check the Messenger service on a remote computer (you obviously need the correct rights on the remote machine);

sc \\ query Messenger | FIND "STATE" > service_state.txt
type service_state.txt | find "4"

IF ERRORLEVEL 255 GOTO Running
IF ERRORLEVEL 1 GOTO Problem

:Running
echo Service is running
goto end

:Problem
echo Service Problem
goto End


:End
exit

Thought this may be worth posting if someone's having a hard time with errorlevels!

No comments: