windows服务开发(一、安装)

最近由于工作需要,写了一个windows服务程序,有许多经验,我会陆续写出来。
请原谅我从安装谈起,因为我一直有一个误区:只要从System.ServiceProcess.ServiceBase继承一个类并编译好就可以用.net提供的命令行程序InstallUtil.exe安装了。经过尝试,发现如果仅仅做了这样的一个类是无法用InstallUtil.exe安装的,在安装时会输出下面的信息:

D:\>installutil windowsservice2.exe Microsoft (R) .NET Framework Installation utility Version 1.1.4322.573 Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. Running a transacted installation. Beginning the Install phase of the installation. See the contents of the log file for the d:\windowsservice2.exe assembly's progr ess. The file is located at d:\windowsservice2.InstallLog. Installing assembly 'd:\windowsservice2.exe'. Affected parameters are: assemblypath = d:\windowsservice2.exe logfile = d:\windowsservice2.InstallLog No public installers with the RunInstallerAttribute.Yes attribute could be found in the d:\windowsservice2.exe assembly. The Install phase completed successfully, and the Commit phase is beginning. See the contents of the log file for the d:\windowsservice2.exe assembly's progr ess. The file is located at d:\windowsservice2.InstallLog. Committing assembly 'd:\windowsservice2.exe'. Affected parameters are: assemblypath = d:\windowsservice2.exe logfile = d:\windowsservice2.InstallLog No public installers with the RunInstallerAttribute.Yes attribute could be found in the d:\windowsservice2.exe assembly. Remove InstallState file because there are no installers. The Commit phase completed successfully. The transacted install has completed.
这是因为installUtil.exe会用反射的方法去查找所有把RunInstallerAttribute设置为true的System.Configuration.Install.Installer类型,并执行上面的Install方法,当找不到的时候,安装就失败了。
所以我们必须要写一个从Installer类继承的类来满足installUtil.exe的要求。


windows服务开发(二、调试)
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值