windows服务命令 转载
OnCustomCommand executes when the Service Control Manager (SCM) passes a custom command to the service. Specifies actions to take when a command with the specified parameter value occurs.
The only values for a custom command that you can define in your application or use in OnCustomCommand are those between 128 and 256.
Integers below 128 correspond to system-reserved values.
Create One Windows Service & Implement Below Code in Service :
namespace MyWindowsService
{
public partial class Service1 : ServiceBase
{
public enum SimpleServiceCustomCommands { Command1 = 128, Command2 =129, Command3 = 130};
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
switch(command)
{
case(int)SimpleServiceCustomCommands.Command1:
//Command1 Implementation
break;
case(int)SimpleServiceCustomCommands.Command2:
//Command2 Implementation
break;
case(int)SimpleServiceCustomCommands.Command3:
//Command3 Implementation
break;
default:
break;
}
}
} }
Call Windows Service CustomCommands From User Application :
- Create Service Controller Object
ServiceController Controller = new ServiceController("MyWindowsService");
- Start the Windows Service
Controller.Refresh(); //Gets the current status of service
if (Controller.Status == ServiceControllerStatus.Stopped)
{
Controller.Start();
} - Call CustomCommands Using Controller Object
if (Controller.Status == ServiceControllerStatus.Running)
{
Controller.ExecuteCommand(128);
}
windows服务命令 转载的更多相关文章
- cmd命令行和bat批处理操作windows服务(转载)
一.cmd命令行---进行Windows服务操作 1.安装服务 sc create 服务名 binPath= "C:\Users\Administrator\Desktop\win32srv ...
- 注册tomcat为windows服务(转载)
第一部分 应用场景 需要服务器上Tomcat不显示启动窗口 需要服务器上Tomcat开机自启动 ... 第二部分 配置过程 一.修改配置文件 1 {Tomcat_HOME}/bin/service.b ...
- 删除windows服务命令
打开命令框:输入sc delete 服务名 例如删除elasticsearch-service-x64服务 sc delete elasticsearch-service-x64
- 玩转Windows服务系列——命令行管理Windows服务
说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令,命令行都是非常方便以及强大的工具. 接下来就看一下如何通过cmd命 ...
- 玩转Windows服务系列——命令行管理Windows服务
原文:玩转Windows服务系列——命令行管理Windows服务 说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令, ...
- [转]玩转Windows服务系列——命令行管理Windows服务
本文转自:http://www.cnblogs.com/hbccdf/p/managewindowsservicewithcmd.html 说到Windows服务的管理就不得不说通过命令行的方式管理W ...
- ASP.NET Core Web程序托管到Windows 服务
前言 在 .NET Core 3.1和WorkerServices构建Windows服务 我们也看到了,如何将workerservices构建成服务,那么本篇文章我们再来看看如何将web应用程序托管到 ...
- SC命令---安装、开启、配置、关闭 cmd命令行和bat批处理操作windows服务
一.cmd命令行---进行Windows服务操作 1.安装服务 sc create 服务名 binPath= "C:\Users\Administrator\Desktop\win32s ...
- windows 运行打开服务命令
转载自:http://www.2cto.com/os/201209/157464.html windows运行打开服务命令 Java代码 1. gpedit.msc-----组策略 2. sndr ...
随机推荐
- 【linux基础】V4L2介绍
参考 1. https://www.cnblogs.com/hzhida/archive/2012/05/29/2524351.html 2. https://www.cnblogs.com/hzhi ...
- ORB(oriented FAST and rotated BRIEF)特征提取与检测
ORB采取FAST算法检测特征点,采取BRIEF算法计算特征点描述子. 1.检测特征点 检测候选特征点周围一圈的像素值,若有足够多的像素值与候选特征点的差异都较大,则认为该候选特征点是特征点. 对于上 ...
- php-isset和empty
<?php $a = null; if(isset($a)){ echo "is set"."\n"; } else{ echo "not se ...
- this语句的用法第一、二点
1.this是js的一个关键字,指定一个对象然后去代替他. 函数内的this和函数外的this,函数内的this指向行为发生的主体.函数外的this都指向window没有意思. 例题: functio ...
- c# 敏捷3 连接,批量处理,分页
class Program { public class post { public int id { get; set; } public string name { get; set; } pub ...
- Gource 方便的软件版本可视化录制工具
Gource 是一个特别棒的软件变更可视化录制工具,我们可以使用此工具,方便的将软件的版本变动,录制 为视频 安装 brew install gource brew install ffmpeg ...
- setsockopt调用IP_ADD_MEMBERSHIP出错errno:19 no such device
if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0) { pri ...
- 数据结构(c语言版)代码
第1章 绪论 文档中源码及测试数据存放目录:数据结构\▲课本算法实现\▲01 绪论 概述 第一章作为绪论,主要介绍了数据结构与算法中的一些基本概念和术语.对于这些概念术语 ...
- 20165308《Java程序设计》第7周学习总结
20165308<Java程序设计>第7周学习总结 教材学习内容总结 第十一章:JDBC与MySQL数据库 MySQL数据库管理系统 启动MySQL数据库服务器 MySQL客户端管理工具 ...
- [转]ArrayList的实现原理
1. ArrayList概述: ArrayList是List接口的可变数组的实现.实现了所有可选列表操作,并允许包括 null 在内的所有元素.除了实现 List 接口外,此类还提供一些方法来操作内部 ...