1. 示例源码:WindowsServiceSample
  2. ServiceHelper源码:ServiceHelper

1. 创建Windows Service项目,如图:

2. 配置服务参数

3. 安装,启动,停止,卸载服务

实现代码:

    private string ServicePath => txtServicePath.Text.Trim();
private string ServiceName => "ServiceSample"; private void BtnStart_Click(object sender, EventArgs e)
{
if (!ServiceHelper.IsExisted(ServiceName))
{
MessageBoxHelper.ShowError($"{ServiceName}不存在");
return;
} ServiceHelper.Start(ServiceName);
} private void BtnStop_Click(object sender, EventArgs e)
{
if (!ServiceHelper.IsExisted(ServiceName))
{
MessageBoxHelper.ShowError($"{ServiceName}不存在");
return;
} ServiceHelper.Stop(ServiceName);
} private void BtnInstall_Click(object sender, EventArgs e)
{
if (ServiceHelper.IsExisted(ServiceName))
{
MessageBoxHelper.ShowError($"{ServiceName}已经存在");
return;
} ServiceHelper.Install(ServicePath);
} private void BtnUnInstall_Click(object sender, EventArgs e)
{
if (!ServiceHelper.IsExisted(ServiceName))
{
MessageBoxHelper.ShowError($"{ServiceName}不存在");
return;
} ServiceHelper.Uninstall(ServicePath);
}
}

最新文章

  1. 修改nginx配置文件解决dx2.5下载附件停止不动的问题
  2. Ionic的跨域问题
  3. jQuery.parseJSON(json) 使用方法
  4. Apache Spark BlinkDB
  5. [React] React Fundamentals: Using Refs to Access Components
  6. php 之 json格式
  7. groovy学习(一)列表
  8. struts ajax多级下拉菜单
  9. Spring源码学习相关记录
  10. phpstorm webstorm 常用快捷键总结
  11. [转]微擎MVC
  12. sql字符处理
  13. eclipse 中springboot2.0整合jsp 出现No Java compiler available for configuration options compilerClassName
  14. 高能天气——团队Scrum冲刺阶段-Day 6
  15. 论文笔记:语音情感识别(四)语音特征之声谱图,log梅尔谱,MFCC,deltas
  16. 第三次Scrum编码冲刺!!!
  17. Win10取消开机密码方法
  18. vue封装插件并发布到npm上
  19. 陆续放给大家一些拿钱买的收费的模板,今天先给一个在某销售网站上排行第一的管理端模板 Ace Responsive Admin Template
  20. unity3d 资源文件从MAX或者MAYA中导出的注意事项

热门文章

  1. liteos软件定时器(十)
  2. vim 自定义设置格式
  3. Python元组与字符串操作(10)——冒泡法
  4. Centos 7 修改网卡名称、静态IP
  5. JWT 使用的另一种声音
  6. Ant下载与安装
  7. JAVA HashMap与ConcurrentHashMap
  8. LeetCode 112. Path Sum路径总和 (C++)
  9. [RN] React-Native中Array渲染的优化
  10. <String> 49 87