码迷,mamicode.com
首页 > Windows程序 > 详细

通过代码动态创建Windows服务

时间:2018-04-01 01:06:53      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:sof   root   安装   splay   代码   arp   hashtable   mic   local   

   开发完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());

  

通过代码动态创建Windows服务

标签:sof   root   安装   splay   代码   arp   hashtable   mic   local   

原文地址:https://www.cnblogs.com/liugh/p/8684734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!