Register your app :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\MyAppName
EventMessageFile REG_EXPAND_SZ %SystemRoot%\System32\wshext.dll
TypesSupported REG_DWORD 0x0000001f (31)
External Functions:
Function longptr RegisterEventSource ( &
longptr lpUNCServerName, &
string lpSourceName &
) Library "advapi32.dll" Alias For "RegisterEventSourceW"
Function boolean ReportEvent ( &
longptr hEventLog, &
uint wType, &
uint wCategory, &
ulong dwEventID, &
longptr lpUserSid, &
uint wNumStrings, &
ulong dwDataSize, &
string lpStrings[], &
ulong lpRawData &
) Library "advapi32.dll" Alias For "ReportEventW"
Function boolean DeregisterEventSource ( &
longptr hEventLog &
) Library "advapi32.dll"
Instance Variables:
Constant UInt EVENTLOG_SUCCESS = 0 // Success event
Constant UInt EVENTLOG_ERROR_TYPE = 1 // Error event
Constant UInt EVENTLOG_WARNING_TYPE = 2 // Warning event
Constant UInt EVENTLOG_INFORMATION_TYPE = 4 // Information event
Function:
public function boolean writetoeventlog (unsignedinteger aui_type, string as_message);// -----------------------------------------------------------------------------
// SCRIPT: WriteToEventLog
//
// PURPOSE: This function writes a message to the event log.
//
// ARGUMENTS: aui_type - Use one of the instance constants:
// EVENTLOG_SUCCESS
// EVENTLOG_ERROR_TYPE
// EVENTLOG_WARNING_TYPE
// EVENTLOG_INFORMATION_TYPE
// as_message - The message text
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 12/31/2021 RolandS Initial coding
// -----------------------------------------------------------------------------
Longptr ll_EventLog
String ls_msgtext[], ls_ErrorMsg
// log the message
ls_msgtext[1] = as_message
ll_EventLog = RegisterEventSource(NULL, "MyAppName")
If ll_EventLog > 0 Then
ReportEvent(ll_EventLog, aui_type, &
0, 0, 0, 1, 0, ls_msgtext, 0)
DeregisterEventSource(ll_EventLog)
Else
ls_ErrorMsg = GetLastErrorMsg()
WriteToLogFile("RegisterEventSource Failed: " + ls_ErrorMsg)
Return False
End If
Return True
end function