关于Windows服务的问题 ,如何将一个windows exe 可执行程序安装为一个服务(高人孟子E章请进) 除非在这个windows程序里面设置好,否则一般windows程序是不支持的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以做到,但你必须在你的程序中添加一个Service组件。并且修改你的Main方法。 在Windows服务工程中,建一个安装类让它继承自System.Configuration.Install.Installer类,然后在InitializeComponent方法中声明ServiceProcessInstaller和ServiceInstaller类,然后将这两个对象加到安装类Installers属性集合中.代码如下:[RunInstaller(true)] public class Installer1 : System.Configuration.Install.Installer { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private System.ServiceProcess.ServiceProcessInstaller spInstaller; private System.ServiceProcess.ServiceInstaller sInstaller; public Installer1() { // 该调用是设计器所必需的。 InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化 } #region Component Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { components = new System.ComponentModel.Container(); // 创建ServiceProcessInstaller对象和ServiceInstaller对象 this.spInstaller = new System.ServiceProcess.ServiceProcessInstaller(); this.sInstaller = new System.ServiceProcess.ServiceInstaller(); // 设定ServiceProcessInstaller对象的帐号、用户名和密码等信息 this.spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.spInstaller.Username = null; this.spInstaller.Password = null; // 设定服务名称 this.sInstaller.ServiceName = "FileMonitorService"; // 设定服务的启动方式 this.sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic; this.Installers.AddRange( new System.Configuration.Install.Installer[] {this.spInstaller, this.sInstaller }); } #endregion }注意:类头前面的[RunInstaller(true)]必须得写,这是正确执行安装的前提.打开.Net的SDK命令提示,输入installutil FileMonitorService.exe,这里的FileMonitorService.exe是相对路径名.输入命令之后就可以安装完成 另有一种办法可以不写代码就可以安装windows服务在注册表中找到:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services新建一个文件夹,在这个文件夹建立几个项目:1.Description这是windows服务的描述2.DisplayName这是windows服务的显示名3.ErrorControl是否提供错误控制4.ImagePath这是windows服务的绝对路径5.Start这是windows服务的启动类型6.Type这是windows服务的类型7.ObjectName是windows服务的帐户类型.注意:文件夹的名称就是windows服务真实名称.然后,重启一下机子就安装成功. 【求助】尝试读取或写入受保护的内存。的问题 C#服务程序,自己重启,怎样实现,在线等!谢谢 服务引用问题? 模拟登录问题 在线更新问题 ORACLE请教一条SQL查询,关于3表关联的统计 按钮绘制半透明PNG图像的问题 vss6.0和2005协作开发-网站的目录下会有一个网站同名的子目录 这是为何? tcpclient连接超时怎么设置? WPF三维坐标均匀补点算法 没有分了,求在.net中使用word控件的方法及那里可以下到这个控件 聊天室中,Remoting客户端第二次登录无法收到消息
[RunInstaller(true)] public class Installer1 : System.Configuration.Install.Installer { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private System.ServiceProcess.ServiceProcessInstaller spInstaller; private System.ServiceProcess.ServiceInstaller sInstaller; public Installer1() { // 该调用是设计器所必需的。 InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化 } #region Component Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { components = new System.ComponentModel.Container(); // 创建ServiceProcessInstaller对象和ServiceInstaller对象 this.spInstaller = new System.ServiceProcess.ServiceProcessInstaller(); this.sInstaller = new System.ServiceProcess.ServiceInstaller(); // 设定ServiceProcessInstaller对象的帐号、用户名和密码等信息 this.spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.spInstaller.Username = null; this.spInstaller.Password = null; // 设定服务名称 this.sInstaller.ServiceName = "FileMonitorService"; // 设定服务的启动方式 this.sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic; this.Installers.AddRange( new System.Configuration.Install.Installer[] {this.spInstaller, this.sInstaller }); } #endregion }
注意:类头前面的[RunInstaller(true)]必须得写,这是正确执行安装的前提.
打开.Net的SDK命令提示,输入installutil FileMonitorService.exe,这里的FileMonitorService.exe是相对路径名.输入命令之后就可以安装完成
在注册表中找到:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services
新建一个文件夹,在这个文件夹建立几个项目:
1.Description这是windows服务的描述
2.DisplayName这是windows服务的显示名
3.ErrorControl是否提供错误控制
4.ImagePath这是windows服务的绝对路径
5.Start这是windows服务的启动类型
6.Type这是windows服务的类型
7.ObjectName是windows服务的帐户类型.
注意:文件夹的名称就是windows服务真实名称.
然后,重启一下机子就安装成功.