• windowsService 程序


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace WindowsServiceTest
    {
        public partial class Service1 : ServiceBase
        {
            public Service1()
            {
                InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
                Console.WriteLine("ss");
                WriteLog("service启动了。");
            }
    
            protected override void OnStop()
            {
                WriteLog("service停止了。");
            }
    
            public void WriteLog(string str)
            {
                using (StreamWriter sw = File.AppendText(@"d:service.txt"))
                {
                    sw.WriteLine(str);
                    sw.Flush();
                }
            }  
        }
    }

    六:安装卸载服务

    选择 VS组件 “Visual Studio命令提示(2010)” 工具,并以“管理员身份运行"(win7、win8系统下)。

    注意:这里必须选择“以管理员身份运行”,否则会报错。

      

    从命令行运行 Installutil.exe 目录  命令,以项目中的已编译可执行文件所在的目录作为参数,安装服务:

    1. 方法 1

    因为Installutil.exe程序在 C:WindowsMicrosoft.NETFramework64v4.0.30319 目录下,需要通过cmd命令 "cd" 切换目录。

    从命令行运行 Installutil.exe /u 目录   命令来卸载服务:

    安装服务: installutil.exe E:XTestDemoX_15_WindowsServiceinDebugX_15_WindowsService.exe

    卸载服务: installutil.exe /u E:XTestDemoX_15_WindowsServiceinDebugX_15_WindowsService.exe

    1. 方法 2

    找到 Installutil.exe 文件,并把它复制到 E:XTestDemoX_15_WindowsServiceinDebug 目录

    现在 Installutil.exe 程序在 E:XTestDemoX_15_WindowsServiceinDebug 目录下,需要通过cmd命令 "cd" 切换目录。

    安装服务: installutil.exe X_15_WindowsService.exe

    卸载服务: installutil.exe X_15_WindowsService.exe

    七:查看服务状态

    在“计算机管理”中,服务 下可以看到刚刚安装的Service服务(cmd命令:services.msc---本地服务设置):

    默认是停止状态。右击,选择“启动”,即可开启服务。

    通过“属性”,可以查看到更详细的信息。

    原文地址:https://www.cnblogs.com/james641/p/6307027.html

  • 相关阅读:
    红线行动开发文档
    团队作业1
    第二次作业:安装VS2015和使用自动测试管理工具
    简单介绍VS2015自动测试工具
    软件工程作业(一)
    三带一队 实验十 团队作业6:团队项目用户验收&BETA冲刺
    《三带一队》【Beta】Scrum meeting 4
    《三带一队》【Beta】Scrum meeting 3
    《三带一队》【Beta】Scrum meeting 2
    《三带一队》【Beta】Scrum meeting 1
  • 原文地址:https://www.cnblogs.com/sxjljj/p/8653900.html
Copyright © 2020-2023  润新知