1

私は小さなバットファイルを書きました:

@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%"

いくつか質問があるので、助けていただければ...

  1. ケース 1: 次のエラーが表示されます。

    エラー: 'MyTest アプリケーション' ログは存在しません。イベントを作成できません。

* 高レベル (c#) コードを使用してイベントログを初期化する唯一の方法は?

  1. case3: 文字列をバット変数と連結するにはどうすればよいですか?

  2. case4: 説明に改行を追加するにはどうすればよいですか?

"exitcode: %boolResult%\n セッション ID は %SessionName%"

それをしませんでした。

ご協力ありがとうございます

4

1 に答える 1

0

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.

于 2010-05-27T09:58:26.147 に答える