我已经使用VS2005模板创build了一个C#服务。 它工作正常,但在Windows服务控件小程序中,该服务的描述是空的。
哪个DVCS适合一个人的.NET商店?
如果我有一个不受操作系统版本支持的API的DllImport(C#.NET),会发生什么情况
从windows服务中杀死一个进程
如何在C#中的系统中获取访问的网站URL
事件日志,P字段中的.NET运行时错误
创建一个ServiceInstaller并设置描述
private System.ServiceProcess.ServiceInstaller serviceInstaller = new System.ServiceProcess.ServiceInstaller(); this.serviceInstaller.Description = "Handles Service Stuff";
为了澄清如何在不使用代码的情况下完成此任务:
将服务安装程序添加到您的项目,如下所述: http : //msdn.microsoft.com/en-us/library/ddhy0byf%28v=vs.80%29.aspx
在设计视图中打开安装程序(例如ProjectInstaller.cs)。
单击服务安装程序组件(例如serviceInstaller1)或右键单击它并选择“属性”。
在Properties窗格中,设置Description和/或displayName(这也是你设置StartType等的地方)描述可能是你想要改变的,虽然如果你想给一个稍微更容易理解的displayName(第一列服务经理)你也可以这样做。
如果需要,打开自动生成的设计器文件(例如ProjectInstaller.Designer.cs)以验证属性是否设置正确。
构建解决方案并使用installutil.exe或其他方式进行安装。
在VS2010中创建服务安装程序项目之后,需要在由VS创建的类中的Install方法中添加一个覆盖,以便为您的服务描述创建注册表项。
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_MACHIneservicesCurrentControlSet 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_MACHInesYstem 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 @R_658_4045@ion 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
你也可以创建一个ServiceInstaller,并在Service安装程序的属性窗口中看到一个你可以设置的描述属性。 如果你不想编码。
您还可以通过右键单击ProjectInstaller类的设计视图中的“serviceInstaller”图标,从IDE中设置服务名称和说明。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。