C# Windows SC.exe如何查询服务上的控制代码
我所做的 我试图在名为C# Windows SC.exe如何查询服务上的控制代码,c#,windows,service,service-control-manager,C#,Windows,Service,Service Control Manager,我所做的 我试图在名为MyTestService的自定义Windows服务中实现ServiceBase.OnCustomCommand(int命令),自定义命令代码如下所示: 我注意到在128处启动自定义命令值是很常见的 我尝试实现如下自定义命令代码: public enum MyCustomCommandCodes { Test1 = 1, Test2 = 2, } protected override void OnCustomCommand(int command) {
MyTestService
的自定义Windows服务中实现ServiceBase.OnCustomCommand(int命令)
,自定义命令代码如下所示:
我注意到在128处启动自定义命令值是很常见的
我尝试实现如下自定义命令代码:
public enum MyCustomCommandCodes
{
Test1 = 1,
Test2 = 2,
}
protected override void OnCustomCommand(int command)
{
switch (command)
{
case (int)MyCustomCommandCodes.Test1:
eventLog1.WriteEntry("Test1");
break;
case (int)MyCustomCommandCodes.Test2:
eventLog1.WriteEntry("Test2");
break;
default:
eventLog1.WriteEntry("default");
break;
}
}
我正在使用Window的命令行实用程序调用OnCustomCommand
当我输入sc control MyTestService 1
时,我发现它实际上停止了服务,而不是调用caseTest1
在我看来,这解释了为什么人们在128
处开始命令值,这是为了防止与已经在使用的代码重叠
我希望能够看到Windows服务已经在使用哪些控制代码
两部分问题:
- 有没有办法查询正在使用的所有代码的列表
- 如果是,是否还有一种方法可以查询每个代码的实际功能
根据@madreflection的评论,该评论指出了控制服务
功能:
用户定义的控制代码范围:128到255
它还说明了为什么sc-control-MyTestService 1
停止服务,这是因为0x1
对应于service\u-control\u-STOP
控制代码
这从另一个方向回答了我的问题,微软给出了一个查找表
任何显示控制代码查询功能的其他答案仍然受欢迎:)这可能会回答本文中的两个问题,以及您发布的另一个问题:谢谢@madreflection!那是一个有用的页面
public enum MyCustomCommandCodes
{
Test1 = 1,
Test2 = 2,
}
protected override void OnCustomCommand(int command)
{
switch (command)
{
case (int)MyCustomCommandCodes.Test1:
eventLog1.WriteEntry("Test1");
break;
case (int)MyCustomCommandCodes.Test2:
eventLog1.WriteEntry("Test2");
break;
default:
eventLog1.WriteEntry("default");
break;
}
}