views:

181

answers:

1

Hello all,

I wrote a small bat file:

@echo off

rem runs the {arg[0].exe} - using its fully qualified name
%~f1

IF %errorlevel% NEQ 0 
(set boolResult=False) 
ELSE 
(set boolResult=True) 


rem case1 
EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

rem case3
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %boolResult%; session id is %SessionName%"

rem case4 
EVENTCREATE /T ERROR /ID 700 /L APPLICATION /D "exitcode: %errorlevel%; session id is %SessionName%"

And I have got some questions, if you could help me out...

  1. case1: I get the following error:

    ERROR: 'MyTest Application' log does not exist. Cannot create the event.

*The only way to initial eventlog in through high-leve (c#) code?

  1. case3: How can I concatenate a string with some bat variable ?

  2. case4: How do I add a newline in the description?

"exitcode: %boolResult%\n session id is %SessionName%"

didn't do that.

Thanks for any assistance

A: 

The only way to initial eventlog in through high-leve (c#) code?

This is correct, there is no command line tool to create new event logs. One option here would be to use a PowerShell script and use the System.Diagnostics.Eventlog class.


case3: How can I concatenate a string with some bat variable ?

The way you do is right, so your log entry text

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: %errorlevel%; session id is %SessionName%"

should expand to:

EVENTCREATE /T ERROR /ID 700 /L "MyTest Application" /D "exitcode: 0; session id is Console"

case4: How do I add a newline in the description?

You can't. There is no way of providing a newline via command line parameters.

Frank Bollack
As for PowerShell, there are cmdlets for dealing with Windows event logs, both legacy and current ones. No need to use the .NET classes.
Joey
@Johannes: Thanks for the mentioning. I'm not very fimilar with PowerShell yet. And you are right, environment variables are not case-sensitive.Don't know why I have thought so up to now.
Frank Bollack