Home > Archive > Visual Basic > February 2006 > Write entery on Application event log in VB6.0
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Write entery on Application event log in VB6.0
|
|
| Lopamudra 2006-02-23, 3:55 am |
| Hi,
I want to write an entry on the application event log for success or error
through my VB 6.0 application. I am not sure if the end user machine will
have .net installed and hence I cannot use those related classes. Can anyone
share with me the code for the event logging into Application event log from
VB 6.0? Also the target machines are Windows 2000 and Windows XP.
-Lopa
| |
| Jan Hyde 2006-02-23, 7:55 am |
| Lopamudra <Lopamudra@discussions.microsoft.com>'s wild
thoughts were released on Thu, 23 Feb 2006 01:19:27 -0800
bearing the following fruit:
>Hi,
>
>I want to write an entry on the application event log for success or error
>through my VB 6.0 application. I am not sure if the end user machine will
>have .net installed and hence I cannot use those related classes. Can anyone
>share with me the code for the event logging into Application event log from
>VB 6.0? Also the target machines are Windows 2000 and Windows XP.
>
Perhaps App.LogEvent is what your after?
Jan Hyde (VB MVP)
--
Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying
to produce bigger and better idiots. So far, the universe is winning.
Rick Cook, Mission Manager, NASA Mars Pathfinder Project
| |
| Lopamudra 2006-02-27, 3:55 am |
| Hi Jan,
App.LogEvent writes to a file on a the harddisk. I want to write to the
"Application" event log.
"Jan Hyde" wrote:
> Lopamudra <Lopamudra@discussions.microsoft.com>'s wild
> thoughts were released on Thu, 23 Feb 2006 01:19:27 -0800
> bearing the following fruit:
>
>
> Perhaps App.LogEvent is what your after?
>
>
>
>
> Jan Hyde (VB MVP)
>
> --
> Programming today is a race between software engineers striving to
> build bigger and better idiot-proof programs, and the universe trying
> to produce bigger and better idiots. So far, the universe is winning.
>
> Rick Cook, Mission Manager, NASA Mars Pathfinder Project
>
>
| |
| Jan Hyde 2006-02-27, 3:55 am |
| Lopamudra <Lopamudra@discussions.microsoft.com>'s wild
thoughts were released on Sun, 26 Feb 2006 21:34:26 -0800
bearing the following fruit:
>Hi Jan,
>
>App.LogEvent writes to a file on a the harddisk.
If your running in the IDE it does, did you try compiling
your app and running that?
J[color=darkred]
> I want to write to the
>"Application" event log.
>
>"Jan Hyde" wrote:
>
Jan Hyde (VB MVP)
--
Dark Ages: Knight Time (Stan Kegel)
| |
| Lopamudra 2006-02-27, 7:55 am |
| Hi Jan,
Sorry to have just stated a part of it. The App.Logevent does write to the
event log but the problem is that you cannot give a customized source name or
anything.
"Jan Hyde" wrote:
> Lopamudra <Lopamudra@discussions.microsoft.com>'s wild
> thoughts were released on Sun, 26 Feb 2006 21:34:26 -0800
> bearing the following fruit:
>
>
> If your running in the IDE it does, did you try compiling
> your app and running that?
>
> J
>
>
> Jan Hyde (VB MVP)
>
> --
> Dark Ages: Knight Time (Stan Kegel)
>
>
| |
| Schmidt 2006-02-27, 7:55 am |
|
"Lopamudra" <Lopamudra@discussions.microsoft.com> schrieb im Newsbeitrag
news:077B8B6A-19B9-41EB-BC7E-6F775272BF08@microsoft.com...
> Hi Jan,
>
> Sorry to have just stated a part of it. The App.Logevent does
> write to the event log but the problem is that you cannot give
> a customized source name or anything.
Try this code instead (uses msvbvm60 as the EventDll):
Option Explicit
Private Declare Function RegisterEventSource Lib "advapi32" Alias _
"RegisterEventSourceA" (ByVal lpUNCServerName As String, _
ByVal lpSourceName As String) As Long
Private Declare Function DeregisterEventSource Lib "advapi32" _
(ByVal hEventLog As Long) As Long
Private Declare Function ReportEvent Lib "advapi32" Alias _
"ReportEventW" (ByVal hEventLog&, ByVal wType%, ByVal wCategory%, _
ByVal dwEventID&, ByVal lpUserSid As Any, ByVal wNumStrings%, _
ByVal dwDataSize&, plpStrings As Any, lpRawData As Any) As Boolean
Private Declare Function RegOpenKey Lib "advapi32" Alias "RegOpenKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult&) As Long
Private Declare Function RegCloseKey& Lib "advapi32" (ByVal hKey&)
Private Declare Function RegCreateKey Lib "advapi32" Alias _
"RegCreateKeyA" (ByVal hKey&, ByVal lpSubKey$, phkResult&) As Long
Private Declare Function RegSetValueEx Lib "advapi32" Alias _
"RegSetValueExA" (ByVal hKey&, ByVal lpValueName$, ByVal Reserved&, _
ByVal dwType&, lpData As Any, ByVal cbData&) As Long
Private Const HKLM& = &H80000002
Public Enum LogTypes
EVENTLOG_ERROR = 1
EVENTLOG_WARNING = 2
EVENTLOG_INFORMATION = 4
End Enum
Public Sub LogEvent(ByVal EvtString As String, LogType As LogTypes)
Dim hEventLog As Long, RegKey As String, EvtDll As String, hK&
Const EvPath$ = " System\CurrentControlSet\Services\Eventl
og\Application\"
hEventLog = RegisterEventSource(vbNullString, App.Title)
If hEventLog = 0 Then Exit Sub
RegKey = EvPath & App.Title
EvtDll = "%SystemRoot%\System32\msvbvm60.dll"
If RegOpenKey(HKLM, RegKey, hK) Then 'if not yet existent
If RegCreateKey(HKLM, RegKey, hK) Then Exit Sub
RegSetValueEx hK, "EventMessageFile", 0, 1, ByVal EvtDll, Len(EvtDll)
RegSetValueEx hK, "TypesSupported", 0, 4, 4&, 4
RegCloseKey hK
Else
RegCloseKey hK
End If
EvtString = Split(",Error:,Warning:,,Information:", ",")(LogType) _
& vbCrLf & vbCrLf & EvtString
ReportEvent hEventLog, LogType, 0, 1, 0&, 1, 0, StrPtr(EvtString), 0&
DeregisterEventSource hEventLog
End Sub
Olaf
|
|
|
|
|