zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    postgresql 简单入门
    自用 docker-compose
    前后端分离 开发环境通过CORS实现跨域联调
    导出 java.io.IOException: 权限不够
    mysql 数值与字符类型 长度梳理
    easyui input未设id导致的问题
    springmvc处理url请求步骤
    js中的变量提升(hoisting)
    auto semicolon insertion 自动分号补齐的坑
    $.ajax dataType设置为json 回调函数不执行
  • 原文地址:https://www.cnblogs.com/sxjljj/p/8653900.html
Copyright © 2011-2022 走看看