问题描述
遵循的介绍,我已经在VS10中创建了一个安装项目,旨在添加自定义操作。该自定义操作有望在以管理员身份运行时(即在安装过程中)添加一个EventLog,而不是让我的应用在具有UAC的操作系统上引发异常。
Following the advice of Henk, I've created a Setup Project in VS10 with the aim of adding a custom action. This custom action will hopefully add an EventLog whilst running as admin (ie during installation) rather than having my app throw an exception on OSes with UAC.
不幸的是,我不通常可以访问使用UAC的操作系统。下次,我希望安装会顺利进行。
Unfortunately, I don't ordinarily have access to an OS that uses UAC. The next time I do, I hope the installation will go smoothly.
考虑到这一点,下面的代码中有明显不正确的地方吗?
With that in mind, is there anything in the below code which is obviously wrong?
using System;
using System.Diagnostics;
namespace EventLogCreator
{
class Program
{
static void Main(string[] args)
{
switch (args[0])
{
case "-i":
if (!EventLog.Exists("SSD Log"))
{
Console.WriteLine("Log not found, creating.");
EventLog.CreateEventSource("setup", "SSD Log");
}
break;
case "-u":
if (EventLog.Exists("SSD Log"))
{
Console.WriteLine("Log found, removing.");
EventLog.Delete("SSD Log");
}
break;
}
}
}
}
该项目的输出被吸收到安装项目中。然后,我有两个自定义操作:
The output of this project is sucked into the setup project. I then have two custom actions:
- 在安装时使用 -i作为参数
- 在以 -u作为参数的卸载中
我不希望有免费的代码审查,但我正在冒险这里不为人所知,因此,如果我丢错了垃圾,我将不胜感激。
I'm not expecting a free code review, but I'm venturing into the unknown here, so I'd appreciate a heads up if I'm humping the wrong bit of trash.
PS我特别担心自己指定实际的日志名称,而不是实际的来源。这会发生吗?
推荐答案
使用系统中的 EventLogInstaller可能会更好。诊断程序集。
You will probably be better off using the "EventLogInstaller" found in the "System.Diagnostics" assembly.
在创建自定义组件,然后将事件日志组件添加到设计图面时,可以看到此实现。组件,然后在属性窗口中单击添加安装程序链接/命令。这将添加一个项目安装程序组件,其中将包含事件日志安装程序组件。
You can see a implementation of this when you create a custom component, then adding a event log component to the design surface, fill in the properties for the component, then click on the "Add Installer" link/command in property window. This will add a project installer component, which will contain a event log installer component.
事件日志安装程序组件是您所需要的,基本上是Windows安装程序。创建Windows安装程序包(MSI)时可以运行的操作。您要做的就是在Visual Studio部署项目的自定义操作编辑器中指定安装程序操作。 MSDN库中有很多有关自定义操作的信息。
The event log installer component is what you are looking for, basically it is a windows installer action that can be run when you create a windows installer package (MSI). All you have to do is specify the installer action in the "Custom Actions Editor" of your visual studio deployment project. There is quite a bit of information regarding custom actions in the MSDN library.
还请查看以下内容:
安装程序工具(Installutil.exe)-msdn.microsoft.com/zh-cn/library/50614e95(VS.80).aspx
Installer Tool (Installutil.exe) - msdn.microsoft.com/en-us/library/50614e95(VS.80).aspx
这篇关于这段代码会在安装时创建一个EventLog吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!