Someone please tell me why errorlevel does not return correct value.

  • Thread starter Thread starter mikhlove
  • Start date Start date
M

mikhlove

Trying to get this to work, but the IF ERRORLEVEL test is not working. The errorlevel that comes back from the find command is always 0.

Thanks to anyone that can help.


@echo off
SETLOCAL ENABLEEXTENSIONS

SETLOCAL ENABLEDELAYEDEXPANSION


FOR /F %%a IN (Alluserlist.txt) do (
@net user %%a /DOMAIN > Domaindata\%%a.txt
)

FOR /R "C:\Documents and Settings\me\My Documents\DomainData" %%a in (*.txt) DO (
Echo %%a
Find /I "Account active Yes" "%%a"

rem **** WHY AM I ALWAYS GETTING ERRORLEVEL 0 HERE ****
rem **** NO MATTER IF THE ACCOUNT IS ACTIVE OR NOT ****
rem **** It works fine if it is not in a FOR LOOP, and only tests against one file ****
ECHO ERRORLEVEL = %ERRORLEVEL%

rem **** I Know the above echo will change the errorlevel, but it is there just as a test ****
rem **** Until I can get this working. ****
IF %ERRORLEVEL% EQU 0 (Echo %%a >> StillAValidUser.txt) ELSE (Echo %%a >> NoLongerAValidUser.txt)
)
pause
endlocal
 
On Sat, 1 Dec 2012 04:40:05 -0800 (PST), "(e-mail address removed)"
Trying to get this to work, but the IF ERRORLEVEL test is not working. The errorlevel that comes back from the find command is always 0.

Thanks to anyone that can help.


@echo off
SETLOCAL ENABLEEXTENSIONS

SETLOCAL ENABLEDELAYEDEXPANSION


FOR /F %%a IN (Alluserlist.txt) do (
@net user %%a /DOMAIN > Domaindata\%%a.txt
)

FOR /R "C:\Documents and Settings\me\My Documents\DomainData" %%a in (*.txt) DO (
Echo %%a
Find /I "Account active Yes" "%%a"

rem **** WHY AM I ALWAYS GETTING ERRORLEVEL 0 HERE ****
rem **** NO MATTER IF THE ACCOUNT IS ACTIVE OR NOT ****
rem **** It works fine if it is not in a FOR LOOP, and only tests against one file ****
ECHO ERRORLEVEL = %ERRORLEVEL%

rem **** I Know the above echo will change the errorlevel, but it is there just as a test ****
rem **** Until I can get this working. ****
IF %ERRORLEVEL% EQU 0 (Echo %%a >> StillAValidUser.txt) ELSE (Echo %%a >> NoLongerAValidUser.txt)
)
pause
endlocal

See the responses to your multiposted message in one of the other
groups you posted it to (under another nickname no less).

In the future, please don't multipost. If the post is applicable to
more than one group, crosspost it to those groups.

--
Zaphod

Adventurer, ex-hippie, good-timer (crook? quite possibly),
manic self-publicist, terrible bad at personal relationships,
often thought to be completely out to lunch.
 
Back
Top