Windows Service 学习系列(二):C# windows服务:安装、卸载、启动和停止Windows Service

一、通过CMD安装、卸载、启动、停止Windows Service  

  方法一

  1.以管理员身份运行cmd

  2.安装windows服务

      切换cd C:\Windows\Microsoft.NET\Framework\v4.0.30319(InstallUtil.exe的路径下,注意InstallUtil.exe的版本号需要和项目的版本号相同)

  3.安装windows服务

      InstallUtil.exe D:\SimpleService\SimpleService\bin\Debug\SimpleService.exe(项目的路径)

(安装过程中出现的错误:Window Service Install "帐户名无效或不存在,或者密码对于指定的帐户名无效。" 解决方法:填用户名时,要在前面加上 .\)

  4.启动windows服务

      net start Servive1(服务名称) 

  5.卸载windows服务

      InstallUtil.exe /u D:\SimpleService\SimpleService\bin\Debug\SimpleService.exe

  方法二  

  1、找到 Installutil.exe 文件,并把它复制到 D:\SimpleService\SimpleService\bin\Debug\目录

  2、现在 Installutil.exe 程序在 D:\SimpleService\SimpleService\bin\Debug 目录下,需要通过cmd命令 "cd" 切换到该目录下。

  3、安装服务:
    installutil.exe SimpleService.exe

  4、卸载服务:
    installutil.exe SimpleService.exe

二、通过程序安装、卸载、启动、停止Windows Service

  

猜你喜欢

转载自www.cnblogs.com/qtiger/p/9897517.html
今日推荐