您的位置:首页 > 编程语言

通过代码动态创建Windows服务

2020-01-15 06:37 113 查看

   开发完Windows服务后,一般通过如下命令进行注册Windows服务

@echo off
%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\installutil.exe %~dp0\服务程序.exe
pause

 除了脚本的方式,通过代码,也可以注册Windows服务:

var ti = new TransactedInstaller();

ti.Installers.Add(new ServiceProcessInstaller
{
Account = ServiceAccount.LocalSystem
});

ti.Installers.Add(new ServiceInstaller
{
DisplayName = displayName,
ServiceName = serviceName,
Description = description,
//运行方式
StartType = ServiceStartMode.Automatic
});

ti.Context = new InstallContext();

ti.Context.Parameters["assemblypath"] = 要安装的Windows服务实现dll或exe路径;

ti.Install(new Hashtable());

  

转载于:https://www.cnblogs.com/liugh/p/8684734.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
an7800666 发布了0 篇原创文章 · 获赞 1 · 访问量 1994 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐