Windows service custom commands from command line

十年热恋 提交于 2020-01-13 06:32:25

问题


I've implemented a Windows Service with custom commands overriding OnCustomCommand method.

I can access these custom commands from another .net application with:

ServiceController Controller = new ServiceController("MyWindowsService");
if (Controller.Status == ServiceControllerStatus.Running)
  {
      Controller.ExecuteCommand(128);
  }

But, can I access these custom commands from the command line (cmd) the same way I can start/stop/... the service?

EDIT: (Without creating a middleware application to handle the service, just with standard tools)


回答1:


You can use the Service Control command line tool sc

> sc control MyWindowsService 128

(Under the hood everything is using Win32's ControlService API.)



来源:https://stackoverflow.com/questions/33888866/windows-service-custom-commands-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!