4

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?
4

2 回答 2

0

向 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MY_CUSTOM_SOURCE_NAME_HERE 添加一个空的注册表项似乎可以正常工作。

于 2013-02-26T22:00:12.413 回答
0

您也可以尝试 EventLogInstaller 类中的方法: https ://msdn.microsoft.com/en-us/library/system.diagnostics.eventloginstaller (v=vs.90).aspx(安装过程中需要管理员权限)

也可能对使用演练中所述的 ProjectInstaller 类感兴趣:在组件设计器中创建 Windows 服务应用程序: https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx? cs-save-lang=1&cs-lang=vb#code-snippet-2

抱歉 - 刚刚看到您关于 Windows 窗体的注释。以上仅适用于 Windows 服务

于 2015-06-10T02:29:47.113 回答