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:\Windows\Microsoft.NET\Framework64\v4.0.30319\ 目录下,需要通过cmd命令 "cd" 切换目录。

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

安装服务: installutil.exe E:\XTestDemo\X_15_WindowsService\bin\Debug\X_15_WindowsService.exe

卸载服务: installutil.exe /u E:\XTestDemo\X_15_WindowsService\bin\Debug\X_15_WindowsService.exe

1. 方法 2

找到 Installutil.exe 文件,并把它复制到 E:\XTestDemo\X_15_WindowsService\bin\Debug\ 目录

现在 Installutil.exe 程序在 E:\XTestDemo\X_15_WindowsService\bin\Debug\ 目录下,需要通过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

windowsService 程序的更多相关文章

  1. HttpContext.Current 的缺陷

    了解ASP.NET的开发人员都知道它有个非常强大的对象 HttpContext,而且为了方便,ASP.NET还为它提供了一个静态属性HttpContext.Current来访问它,今天的博客打算就从H ...

  2. HttpContext.Current并非无处不在

    阅读目录 开始 无处不在的HttpContext HttpContext.Current到底保存在哪里? HttpContext并非无处不在! 如何获取文件绝对路径? 异步调用中如何访问HttpCon ...

  3. VS2010关于WindowsService 制作安装程序包,无法自动install的问题解决方法

    当添加了 安装项目后,需要做2个步骤的操作,第一是 右键点击 “视图”---“文件系统”,添加“项目输出“,好了后,再右键点击 “视图”---“自定义操作” 在安装中添加自定义操作,将刚才的”项目输出 ...

  4. WindowsService(Windows服务)开发步骤附Demo

    1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service1服务文件,编写service1.cs类文件,不是Service1[设计].然后修改OnSta ...

  5. WindowsService 安装后报错: 无法启动计算机“.”上的服务 解决方案

    问题 : 根据客户的需求做了一个小程序,需要有对WindowsService 安装,卸载,启动,停止的操作. 编译好之后在我的工程内直接Run 没问题.直接在\bin\Debug 点小程序运行,任何操 ...

  6. 如何在VS2013中新建WindowsService定时任务

    http://jingyan.baidu.com/article/cd4c2979e9330d756f6e6070.html 很多人都想做定时任务,但是没有不知道如何下手,现在就用WindowsSer ...

  7. WindowsService(Windows服务)开发步骤附Demo 【转】

    转http://www.cnblogs.com/moretry/p/4149489.html 1.打开VS,新建项目,选择Windows服务,然后设置目录及项目名称后点击确定. 2.展开Service ...

  8. WindowsService的调试方法

    本人转载:http://www.cnblogs.com/xiebin1986/archive/2011/12/15/2288893.html 调试WindowsService,以前用过一个附加到进程的 ...

  9. WindowsService服务的C#实现

    WindowsService(简称服务,下同)是目前做客户端软件后台运行功能的非常好的选择,本文基本解决了服务的创建和编写,代码控制服务的安装.卸载.启动.停止等,为服务传递参数,其他注意事项等 1. ...

随机推荐

  1. floyd的魔改应用——洛谷P2419 [USACO08JAN]牛大赛Cow Contest 题解

    想找原题请点击这里:传送门 原题: 题目背景 [Usaco2008 Jan] 题目描述 N ( ≤ N ≤ ) cows, conveniently numbered ..N, are partici ...

  2. 【Python矩阵及其基础操作】【numpy matrix】

    一.矩阵生成 1.numpy.matrix: import numpy as np x = np.matrix([ [1, 2, 3],[4, 5, 6] ]) y = np.matrix( [1, ...

  3. TimeSeriesEditor时间序列编辑软件之实战ReoGrid表格控件和Zedgraph绘图控件

    最近用ReoGrid表格控件和Zedgraph绘图控件写了一个TimeSeriesEditor时间序列编辑软件,如下图. 目的就是体验一下这两个空间的用法,感觉还是挺好用的, 关于软件的使用说明可以访 ...

  4. December 21st, Week 51st Saturday, 2019

    May the odds be ever in your favor. 愿好运永远眷顾你. From The Hunger Games. May we all have good luck, and ...

  5. php 随机生成汉字

    function getChar($num) // $num为生成汉字的数量 { $b = ''; for ($i=0; $i<$num; $i++) { // 使用chr()函数拼接双字节汉字 ...

  6. Plastic Sprayer Manufacturer - How Does The Sprayer Work?

    The Plastic Sprayers Manufacturer   stated that the sprayer is a very useful type of machine and a g ...

  7. 第2节 Scala中面向对象编程:7、继承的概念以及override和super关键字;8、isInstanceOf 和 asInstanceOf关键字

    6.3.   Scala面向对象编程之继承 6.3.1.     Scala中继承(extends)的概念 Scala 中,让子类继承父类,与 Java 一样,也是使用 extends 关键字: 继承 ...

  8. 树莓派4B踩坑指南 - (4)输入法和字体

    输入法和字体 fcitx 安装谷歌输入法和sunpinyin,哪个不用可以装完卸载: sudo apt-get install fcitx fcitx-googlepinyin fcitx-modul ...

  9. 「Luogu P3168 [CQOI2015]任务查询系统」

    介绍本题的两种做法: 方法1 前置芝士 线段树:一个很重要的数据结构. 树状数组:一个很重要的数据结构. 具体实现 区间修改,单点查询很容易就会想到树状数组了,至于查询前k个数的和又可以丢给权值线段树 ...

  10. 图解jvm--(三)类加载与字节码技术

    类加载与字节码技术 1.类文件结构 根据 JVM 规范,类文件结构如下 ClassFile { u4 magic; //魔数 u2 minor_version; //小版本号 u2 major_ver ...