Create event log source as part of installation - Windows Forms application, vs deployment project

I have a vb.net form application that I am deploying using a visual studio deployment project. The application must write event logs to the application log in the event viewer. For the reasons explained here I need to create an event source during the installation process. Something like this to run as part of the installer

If Not EventLog.SourceExists(My.Application.Info.ProductName) Then EventLog.CreateEventSource(My.Application.Info.ProductName, "Application") End If 

This code must be run during installation with elevated privileges. So my questions are:

  • How to execute this code above as part of the setup program?
  • How do I get the installer to execute the UAC prompt so that this code runs as part of the installation?
+4
source share
2 answers

Adding an empty registry key to HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ services \ eventlog \ Application \ MY_CUSTOM_SOURCE_NAME_HERE seems to work fine.

0
source

You can also try the approach in the EventLogInstaller class: https://msdn.microsoft.com/en-us/library/system.diagnostics.eventloginstaller(v=vs.90).aspx (administrator permissions required during installation)

It may also be interesting to use the ProjectInstaller class, as described in the Walkthrough. Creating a Windows service application in Component Designer: https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code- snippet-2

Sorry - just saw your note in Windows Forms. Above all good for windows service

0
source

Source: https://habr.com/ru/post/1345469/


All Articles