程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> 給windows服務添加描述

給windows服務添加描述

編輯:關於.NET

最近寫了個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 文件中的。

也許有更好的辦法,望大家指教。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved