我已经使用VS2005模板创建了一个C#服务。它工作正常,但在Windows服务控件小程序中该服务的描述是空的。在.net中设置windows服务描述的最佳方式是什么?
回答
创建的ServiceInstaller并设置描述
private System.ServiceProcess.ServiceInstaller serviceInstaller =
new System.ServiceProcess.ServiceInstaller();
this.serviceInstaller.Description = "Handles Service Stuff";
你也可以创建一个的ServiceInstaller和服务安装程序的属性窗口中,您将看到您可以设置一个描述属性。如果你不想编码它。
我很确定我尝试设置服务和服务安装程序中的每个描述属性,并且它们都没有工作。也许我错过了这一个。 – 2009-03-05 22:42:37
要如何做到这一点不使用代码澄清:
添加一个服务安装到您的项目如下所述:http://msdn.microsoft.com/en-us/library/ddhy0byf%28v=vs.80%29.aspx
打开在设计安装(如ProjectInstaller.cs)视图。
单击服务安装程序组件(例如serviceInstaller1)或右键单击它并选择“属性”。
在属性窗格中,设置Description和/或DisplayName(这也是您设置StartType等的地方)描述可能是您想要更改的所有内容,但如果您想给出稍微更易于理解的DisplayName (服务经理的第一列),你也可以这样做。
如果需要,请打开自动生成的设计器文件(例如ProjectInstaller.Designer.cs)以验证属性设置是否正确。
构建解决方案并使用
installutil.exe
或其他方法进行安装。
在创建在VS2010您的服务安装的项目,你需要一个覆盖添加到由VS创建为您服务描述注册表项类中的方法安装。
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
using Microsoft.Win32;
namespace SomeService
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
/// <summary>
/// Overriden to get more control over service installation.
/// </summary>
/// <param name="stateServer"></param>
public override void Install(IDictionary stateServer)
{
RegistryKey system;
//HKEY_LOCAL_MACHINE\Services\CurrentControlSet
RegistryKey currentControlSet;
//...\Services
RegistryKey services;
//...\<Service Name>
RegistryKey service;
// ...\Parameters - this is where you can put service-specific configuration
// Microsoft.Win32.RegistryKey config;
try
{
//Let the project installer do its job
base.Install(stateServer);
//Open the HKEY_LOCAL_MACHINE\SYSTEM key
system = Registry.LocalMachine.OpenSubKey("System");
//Open CurrentControlSet
currentControlSet = system.OpenSubKey("CurrentControlSet");
//Go to the services key
services = currentControlSet.OpenSubKey("Services");
//Open the key for your service, and allow writing
service = services.OpenSubKey("MyService", true);
//Add your service's description as a REG_SZ value named "Description"
service.SetValue("Description", "A service that does so and so");
//(Optional) Add some custom information your service will use...
// config = service.CreateSubKey("Parameters");
}
catch (Exception e)
{
throw new Exception(e.Message + "\n" + e.StackTrace);
}
}
}
}
http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.aspx
http://www.codeproject.com/KB/dotnet/dotnetscmdescription.aspx
- 1. 在C++中设置Windows服务描述
- 2. 设置dev-env构建Windows服务的最佳方式是什么?
- 3. 什么是从Windows Mobile调用Web服务的最佳方式(.NET 3.5)
- 4. 在.NET中注册现有Windows服务的最佳方法是什么?
- 5. 在Python中获取网站描述的最佳方式是什么?
- 6. 什么是最佳的计时器间隔? .NET Windows服务
- 7. .NET - 检查和控制Windows服务的最佳库是什么?
- 8. 在.Net中创建提醒服务的最佳方式是什么?
- 9. 在Windows机器上互连2个.NET服务的最佳方法是什么?
- 10. 在Grails中使用Web服务的最佳方式是什么?
- 11. 在服务器中实现AutoComplete的最佳方式是什么?
- 12. 在python中使用web服务的最佳方式是什么?
- 13. 在Python中实现Web服务的最佳方式是什么?
- 14. 什么是在grails中使用服务的最佳方式
- 15. 在joomla中制作web服务的最佳方式是什么?
- 16. 匹配FREAK描述符的最佳方法是什么?
- 17. 什么是“嵌入式硬件系统”的最佳描述?
- 18. 什么是在Android中设置通知的最佳方式
- 19. 在QuoteRequest消息中设置SenderSubID的最佳方式是什么?
- 20. 在Windows 7中运行Linux虚拟服务器的最佳方式是什么?
- 21. 为MVC 4设置我的Intranet服务器的最佳方式是什么?
- 22. 什么是在.NET中“平方”图像的最佳方式?
- 23. 设置集成测试服务器的最佳方式是什么?
- 24. 在'n'个服务器中设置Cloudwatch的最佳方法是什么?
- 25. 回滚.net事务的最佳方式是什么?
- 26. WebMatrix中查询WCF服务的最佳方式是什么?
- 27. ping /通知.NET Windows服务的最简单方法是什么?
- 28. 设置“深度”配置选项的最佳方式是什么?
- 29. 什么是当前设置第三方cookie的最佳方式?
- 30. 在.NET XmlDocument中移动“小孩”的最佳方式是什么?
只需添加到这一点,你还可以设置 serviceInstaller.DisplayName = “一些好的显示名称”; – CapBBeard 2009-01-27 21:21:41
exxelent。我正在考虑一些编码将需要ah-la这个解决方案... http://www.codeproject.com/KB/dotnet/dotnetscmdescription.aspx也许这只是VS2003所必需的? – 2009-07-20 01:26:35