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基础】linux远程登录
可以用ssh命令行方式登录.对方需要开启ssh服务. 1. https://blog.csdn.net/zilaike/article/details/78922524 2. https://blog ...
- Python之路,第二十篇:Python入门与基础20
python3 面向对象4 supper 函数 supper(type, obj) 返回绑定超类的实例(要求obj必须为type类型的实例) supper() 返回绑定的超类的实例,等同于(cl ...
- QT学习相关
1. vs2012的编译器对execution_character_set("utf-8")无反应的bug在vs2013中解决 2. 安装上vs2013后,重装的qt插件,发现不能 ...
- fixed不能罩住下面的内容
fix的优先级并不是最高的,所以要设置z-index,比它下面的元素高就能遮住了
- 你不能阻止DOM
浏览器数据库景观 对于外行来说,浏览器数据库的世界可能是一个令人困惑的世界.Lawnchair,PouchDB,LocalForage,Dexie,Lovefield,LokiJS,AlaSQL,Ma ...
- (21)jq动画
jq动画的优点 优点: 1.可以知道动画结束的表示(结束的回调函数) 2.可以利用jq动画插件完成复杂的动画 动画有三个参数:动画的样式是字典.动画持续的事件,动画结束回调函数 <!DOCTYP ...
- (9)SQL的注入(致命的漏洞)
用户登陆网站的时候进行账户验证输入特殊的格式和字符会触发一个漏洞,不需要密码直接登录成功 import pymysql username = input('请输入账号: ')password = in ...
- mysqldump命令之常用模板
##=====================================================## ## 在Master上导出所有数据库 /export/servers/mysql/b ...
- Scala之偏函数Partial Function
https://blog.csdn.net/bluishglc/article/details/50995939 从使用case语句构造匿名函数谈起在Scala里,我们可以使用case语句来创建一个匿 ...
- loki grafana 团队开源的,类似Prometheus 的log 系统
Prometheus 主要面向的是metrics,但是loki 是log,这样加上grafana 强大的可视化以及alert能力, 我们可以做好多事情,loki 的设计来源于Prometheus. 组 ...