Windows service custom commands from command line

2020-07-24 23:13发布

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条回答
放荡不羁爱自由
2楼-- · 2020-07-24 23:43

You can use the Service Control command line tool sc

> sc control MyWindowsService 128

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

查看更多
登录 后发表回答