I am working on a Windows .NET application and I want to write to the Eventlog.
Public Shared Sub WriteExceptionToEventLog(ByVal message As String)
Dim cs As String = "TESTLOG"
Dim elog As New EventLog()
Dim sourceExist As Boolean
Try
sourceExist = EventLog.SourceExists(cs)
Catch ex As Exception
sourceExist = False
End Try
If Not sourceExist Then
Dim ev As New EventLogPermission(EventLogPermissionAccess.Administer, ".")
ev.PermitOnly()
EventLog.CreateEventSource(cs, "TESTLOG")
End If
elog.Source = cs
elog.EnableRaisingEvents = True
EventLog.WriteEntry(cs, message, EventLogEntryType.[Error])
End Sub
But this is not working as the user in Windows 7 need Admin previlage to write to Eventlog. The same was successful when I executed the application with "Run ad Admin" mode.
So is there any way to give Admin privilege for a code segment in vb.net (other than impersonation)?