【发布时间】:2022-01-23 23:09:14
【问题描述】:
我知道会调用一个自定义操作,因为 1) 我可以在日志中看到它,2) 日志报告它正在引发安全异常。
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security, State.
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate)
at System.Diagnostics.EventLog.SourceExists(String source)
at EventTestCustomAction.CustomActions.CreateEventTestEventLog(Session session) in c:\erase\code\EventTest\EventTestCustomAction\CustomAction.cs:line 16
对于我的 Package 元素,我定义了:
<Package InstallerVersion="500" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />
我将自定义操作定义为延迟执行:
<CustomAction Id='CreateLog' BinaryKey='CustomActionDll' DllEntry='CreateEventTestEventLog' Return='check' Execute='deferred'/>
InstallExecuteSequence 定义为:
<InstallExecuteSequence>
<Custom Action="IsPrivileged" Before="AppSearch"><![CDATA[Not Privileged]]></Custom>
<Custom Action="CreateLog" After="InstallFiles" >NOT Installed AND NOT REMOVE</Custom>
</InstallExecuteSequence>
我正在从非提升但具有管理员权限的命令提示符运行。当使用msiexec /i \path\to\installer.msi 运行时,它会提升。在我在那里进行自定义操作之前,安装程序会运行良好并将文件复制到 Program Files 下的正确目录中。
导致异常的 API 是
EventLog.SourceExists("mysourcename");
当然,我可以链接 Wix Util 并使用 <util:EventSource blah blah blah/>,但在这种情况下我有理由不想这样做。 Wix Util 库以某种方式解决了这个问题。几周前,我还尝试查看注册表和当前控件集,以不同方式查看,但由于安全原因,它不允许我打开注册表项。
我原以为安装程序是在使用 LocalSystem 帐户提升后运行的。似乎很明显他们没有。但是 util:EventSource 是如何摆脱它的呢?有没有我在某处遗漏的参数?
【问题讨论】:
标签: wix windows-installer