|
安装
在结束以前,我们来简要介绍一下安装以及称为 installutil.exe的
安装工具。由于此应用程序是 Windows服务,它必须使用installutil.exe
来安装。因此,需要使用一个从 System.Configuration.Install 程序集
中继承的 Installer类:
public class ServiceRegister: Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public ServiceRegister()
{
// 创建服务安装程序
serviceInstaller = new ServiceInstaller();
serviceInstaller.StartType = ServiceStart.Manual;
serviceInstaller.ServiceName = ServiceControl.ServiceControl
Name;
serviceInstaller.DisplayName = ServiceControl.ServiceControl
Desc;
Installers.Add(serviceInstaller);
// 创建进程安装程序
processInstaller = new ServiceProcessInstaller();
processInstaller.RunUnderSystemAccount = true;
Installers.Add(processInstaller);
}
}
如此示例类所示,对于一个 Windows服务,服务和服务进程各需要一
个安装程序,以定义运行服务的帐户。其他安装程序允许注册事件日志和
性能计数器等资源。
总结
从这个 .NET 框架应用程序示例中可以看出,以前只有 Visual C++
程序员能够编写的应用程序,现在使用简单的面向对象程序即可实现。尽
管我们的重点是 C# ,但本文所述的内容也同样适用于 Visual Basic 和
Managed C++.新的 .NET 框架使开发人员能够使用任何编程语言来创建功
能强大、可伸缩的 Windows应用程序和服务。
新的 .NET 框架不仅简化和扩展了编程的种种可能,还能够轻松地将
人们经常遗忘的应用程序检测设备(例如性能监测计数器和事件日志通知)
合并到应用程序中。尽管这里的应用程序没有使用 Windows管理检测设备
(WMI ),但 .NET 框架同样也可以应用它 |
|