Handling errorlevels

November 23, 2009 at 07:20:03
Specs: Windows XP
I have been updating an old batch (2005) that uses various applications from sysinternals. My current problem deals with capturing the default message (which is produced when no valid entries are found that match the requested query) and passing my own message to a log file. For some reason the following code always throws an errorlevel 1. The problem started when I added "set checkSecurityLog=" to the element. This element allows the passing of my own message instead of psloglist default message.

Any ideas?


:: Enable delayed variable expansion
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION


set checkSecurityLog=
for /f "delims=" %%a in ('psloglist.exe -d 30 -i 529 security 2^>nul ^| find /v /i "security log on \\" ') do (
echo %%a
set checkSecurityLog=%%a

)

if not defined checkSecurityLog (echo test)

IF %ERRORLEVEL% NEQ 0 (
echo An exception was thrown by the script. echo error level is !errorlevel!)

echo !errorlevel!
echo.
endlocal
GOTO:EOF


See More: Handling errorlevels

Report •


#1
November 23, 2009 at 09:11:10
I don't have the exe to test it, but a couple things:

In your FOR loop maybe you need tokens=*

Maybe this:

IF %ERRORLEVEL% NEQ 0 (

could be:

IF !ERRORLEVEL! NEQ 0 (


=====================================
Helping others achieve escape felicity

M2


Report •

#2
November 23, 2009 at 09:24:09
I tried tokens=* and !ERRORLEVEL!, but both failed to fix the problem.

Here is the link to the exe: http://live.sysinternals.com/PsLogL...


Report •

#3
November 23, 2009 at 10:49:50
Not sure what this is trying to do but maybe 2^>nul is an issue.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
November 23, 2009 at 11:15:10
2^>nul suppresses the default message (No records in Security event log on) from being written to the console or to my output log files.

find /v /i "security log on \\ - suppresses the text "security log on \\:" from being written to the console or to my output files.

Queries with no valid results produce this message:

Security log on \\:
No records in Security event log on .

Queries with valid results produce a message like this one. The first entry always begins with "Security log on \\:"

Security log on \\:
[63225] Security
Type: AUDIT SUCCESS
Computer: LAB-01
Time: 11/20/2009 19:22:59 ID: 528
User: NETWORK SERVICE\NT AUTHORITY
Successful Logon:
User Name: NETWORK SERVICE
Domain: NT AUTHORITY
Logon ID: (0x0,0x3E4)
Logon Type: 5
Logon Process: Advapi
Authentication Package: Negotiate
Workstation Name:
Logon GUID: -


Report •

#5
November 24, 2009 at 02:23:57
I don't understand the problem. You say it always sets the errorlevel to 1, but which part of the code does this? The executable? Or somewhere in the rest of the batch file?

Report •

#6
November 25, 2009 at 17:17:37
Fixed. The problem was a scripting syntax issue was causing an error to be thrown.

Report •


Ask Question