c#创建Windows service (Windows 服务)基础教程

转自:http://www.cnblogs.com/sorex/archive/2012/05/16/2502001.html

1)创建Windows service项目

二、创建服务安装程序

1)添加安装程序

之后我们可以看到上图,自动为我们创建了ProjectInstaller.cs以及2个安装的组件。

2)修改安装服务名

右键serviceInsraller1,选择属性,将ServiceName的值改为ServiceTest。

3)修改安装权限

右键serviceProcessInsraller1,选择属性,将Account的值改为LocalSystem。

三、写入服务代码

1)打开ServiceTest代码

右键ServiceTest,选择查看代码。

2)写入Service逻辑

四、创建安装脚本(在WindowsServiceTest.exe所在的目录下创建)

在项目中添加2个文件如下(必须是ANSI或者UTF-8无BOM格式):

1)安装脚本Install.bat

 
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe D:\huiyishi\WindowsServiceTest\WindowsServiceTest\bin\Debug\WindowsServiceTest.exe

2)卸载脚本Uninstall.bat

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u D:\huiyishi\WindowsServiceTest\WindowsServiceTest\bin\Debug\WindowsServiceTest.exe

posted @ 2017-11-06 13:49  cacti_vc  阅读(162)  评论(0编辑  收藏  举报