ExecuteCommand 服务控制器 - 无法在服务上执行命令
我正在使用服务控制器的executecommand 函数,如下所示:
ServiceController serviceController = new ServiceController("a Service",
Environment.MachineName);
serviceController.ExecuteCommand(129);
在服务控制器中:
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
// Depending on the integer passed in, the appropriate method is called.
switch (command)
{
case 129:
RestartSpooler();
break;
case 131:
InstallPrinter();
break;
case 132:
DeletePrinter();
break;
}
}
但是,尽管从调用代码中调用了任何命令(代码命中线路,然后跳过,没有例外),但没有任何反应。为什么?这一切都在本地计算机上,我拥有完整的管理员权限。
谢谢
I am using the service controller executecommand function, like so:
ServiceController serviceController = new ServiceController("a Service",
Environment.MachineName);
serviceController.ExecuteCommand(129);
And in the service controller:
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
// Depending on the integer passed in, the appropriate method is called.
switch (command)
{
case 129:
RestartSpooler();
break;
case 131:
InstallPrinter();
break;
case 132:
DeletePrinter();
break;
}
}
However, despite calling any of the commands from the calling code (the code hits the line, then steps over, no exceptions), nothing happens. Why? This is all on the local machine and I have full admin rights.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须尝试对已停止的服务执行命令。添加如下内容:
You must be trying to execute command against a stopped service. Add something like the following:
我还没有找到任何它不起作用的原因。
这是使用自定义命令的 Windows 服务的工作示例
服务安装程序
服务使用情况
I haven't found any reason why it shouldn't work.
Here is the working example of windows service with custom command
Service installer
Service usage