开发者

Create Event Log Source as part of installation - windows forms app, vs deployment project

I have a vb.net windows form app that I a开发者_Python百科m 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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜