核心操作

1、新建一个Windows Service,并将项目名称改为“MyWindowsService”,如下图所示:

使用C#创建Windows服务_windows服务

2、在解决方案资源管理器内将Service1.cs改为MyService1.cs后并点击“查看代码”图标按钮进入代码编辑器界面,如下图所示:

 

 

使用C#创建Windows服务_windows服务_02

 

4、双击项目“MyWindowsService”进入“MyService”设计界面,在空白位置右击鼠标弹出上下文菜单,选中“添加安装程序”,如下图所示:

使用C#创建Windows服务_资源管理器_03

5、此时软件会生成两个组件,分别为“serviceInstaller1”及“serviceProcessInstaller1”,如下图所示:

使用C#创建Windows服务_html_04

6、点击“serviceInstaller1”,在“属性”窗体将ServiceName改为MyService,Description改为我的服务,StartType保持为Manual,如下图所示:

使用C#创建Windows服务_资源管理器_05

使用C#创建Windows服务_资源管理器_06

使用C#创建Windows服务_资源管理器_07

7、点击“serviceProcessInstaller1”,在“属性”窗体将Account改为LocalSystem(服务属性系统级别),如下图所示:

使用C#创建Windows服务_windows服务_08

8、鼠标右键点击项目“MyWindowsService”,在弹出的上下文菜单中选择“生成”按钮,如下图所示:

使用C#创建Windows服务_windows服务_09

9、至此,Windows服务已经创建完毕。

 


树立目标,保持活力,gogogo!