给windows服务添加描述-.NET教程,Asp.Net开发
点击次数:21 次 发布日期:2008-11-22 11:30:36 作者:源代码网
|
源代码网推荐
最近写了个windows服务(windows services),安装了以后,觉得和已有的windows服务不一样。为什么?我的缺少描述,中间一栏是空的。
再看.net的servicebase类没有添加描述的属性。
public class projectinstaller : system.configuration.install.installer中也没有什么属性来添加。从网搜了后才知道要重载projectinstaller 的install和uninstall虚方法。其实重写这些虚方法就是为了在注册表相应服务中加一个键值"description",其值填为相应的描述就可以了。
public override void install(idictionary stateserver) { microsoft.win32.registrykey system, service, config; try { //let the project installer do its job base.install(stateserver); system = microsoft.win32.registry.localmachine.opensubkey("system").opensubkey("currentcontrolset").opensubkey("services"); service = system.opensubkey(this.serviceinstaller1.servicename, true); service.setvalue("description", "服务描述"); //添加额外的键 config = service.createsubkey("additionalinformation"); } catch(exception e) { } } public override void uninstall(idictionary stateserver) { microsoft.win32.registrykey system, currentcontrolset, services, service; try { system = microsoft.win32.registry.localmachine.opensubkey("system"); currentcontrolset = system.opensubkey("currentcontrolset"); services = currentcontrolset.opensubkey("services"); service = services.opensubkey(this.serviceinstaller1.servicename, true); //删除额外的键 service.deletesubkeytree("additionalinformation"); //... } catch(exception e) { } finally { base.uninstall(stateserver); } }
注意这些代码是在projectinstaller 文件中的。
也许有更好的办法,望大家指教
源代码网供稿. |