PDA

View Full Version : Create events in eventlog


emu99
07-04-2008, 06:47 AM
Hi,

since i rather prefer generating events during installations e.g. installation problems, starting, success i made some small function inside global functions, which uses the exe-file eventcreate.exe which comes with windows xp. With this util one can create individual events in eventlog.
during large deployments in company looking up the eventvwr to see what went wrong is in my opionen much fast than searching / looking up the setuplogfile....

so, maybe also others like this function, so here it is:

create inside global functions the function CREATE_EVENT:

function CREATE_EVENT(EVENT_TYPE, EVENT_TXT)
result = File.DoesExist(_SystemFolder.."\\eventcreate.exe");
if (result == true ) then
EVENT_TEXT = " /T " .. EVENT_TYPE .. " /ID 888 /L APPLICATION /SO " .. "\"".."TIVOLI-PACKAGE: "..SessionVar.Expand("%ProductName%").." "..SessionVar.Expand("%ProductVer%").."\"".. " /D " .. "\"" .. EVENT_TXT .. "\"";
File.Run(_SystemFolder.."\\eventcreate.exe", EVENT_TEXT, "", SW_MINIMIZE, true);
end

end


call the function with

as error-type:
EVENT_TYPE="ERROR"; EVENT_TXT="Installation error: " .. STATUS .. " - " .. STATUSMESSAGE ;
CREATE_EVENT(EVENT_TYPE, EVENT_TXT);

or e.g. as information-type:
EVENT_TYPE="INFORMATION"; EVENT_TXT="Installation successful ...";
CREATE_EVENT(EVENT_TYPE, EVENT_TXT);

the variables STATUS and STATUSMESSAGE e.g. can be filled with Application.GetLastError() and tblErrorMessages[error].
On action "at startup" at the beginning i define them, just in case, Trap() wasn't called before using the function CREATE_EVENT, just to make sure, values are not empty... if during Trap() error occured both values with be filled autom. with the errorcode and text which occured...

STATUS = 0;
STATUSMESSAGE = "OK";

for detailed info about eventcreate.exe just call inside cmd eventcreate.exe /? or visit page like this one:
http://windowsitpro.com/windowsscripting/article/articleid/44894/a-windows-2003-and-xp-command-line-tools-sampler.html



In my installations i created a function Trap() in the global functions, which i call after vital operations to check, if error occured, if not silent (using variable _SilentInstall ~= true) error message pops up for 5 secs:


function Trap()
error = Application.GetLastError();
if (error ~= 0) then
if (_SilentInstall ~= true) then
Dialog.TimedMessage("Error occured !", _tblErrorMessages[error], 5000, MB_ICONEXCLAMATION); end
STATUS=error; STATUSMESSAGE=_tblErrorMessages[error]; endend