一个完整的Windows 服务从创建到安装卸载

来源:互联网 发布:淘宝现货是什么意思 编辑:程序博客网 时间:2024/05/16 16:05

第一、创建一个Windows服务

第二、在自动生成的Program类中写你要写的代码

复制代码
using System;using System.Collections.Generic;using System.Linq;using System.ServiceProcess;using System.Text;namespace WindowsTest{    static class Program    {        /// <summary>        /// 应用程序的主入口点。        /// </summary>        static void Main()        {            ServiceBase[] ServicesToRun;            ServicesToRun = new ServiceBase[]             {                 new Service1()             };            ServiceBase.Run(ServicesToRun);        }    }}
复制代码

第三、安装程序
第四、改变一下属性

第五、找到bin文件夹下的文件

第六、输入一下命令

1、输入cmd(命令行),输入cd C:\WINDOWS\Microsoft.NET\Framework\v4.0.303192.0cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

2、InstallUtil "E:\接口\接口测试\WindowsTest\WindowsTest\bin\Debug\WindowsTest.exe"

第七、卸载

InstallUtil/u "E:\接口\接口测试\WindowsTest\WindowsTest\bin\Debug\WindowsTest.exe"

原创粉丝点击