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

第一、创建一个Windows服务

一个完整的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);
        }
    }
}

第三、安装程序一个完整的Windows 服务从创建到安装卸载
第四、改变一下属性

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

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

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

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

第六、输入一下命令

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"

第八、在服务里找到你发布的项目

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

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