6

I have a vb.net windows form app that I am deploying as using the visual studio deployment project. The app needs to write event logs to the application log in the event viewer. For reasons explained here I need to create the 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

That code needs to be run during the installer with elevated privileges. So my questions are:

  1. How do I execute that code above as part of the installer?
  2. How do I get the installer to do the UAC prompt to allow that code to run as part of the installation?
avword
  • 209
  • 1
  • 5
  • 12

2 Answers2

1

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

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
0

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

May also be interested in using ProjectInstaller class as described in Walkthrough: Creating a Windows Service Application in the 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 re Windows Forms. Above only good for Windows Service

user3085342
  • 86
  • 1
  • 6