Windows 从命令行服务自定义命令
Windows service custom commands from command line
我已经实现了一个 Windows 服务,其中包含覆盖 OnCustomCommand 方法的自定义命令。
我可以从另一个 .net 应用程序访问这些自定义命令:
ServiceController Controller = new ServiceController("MyWindowsService");
if (Controller.Status == ServiceControllerStatus.Running)
{
Controller.ExecuteCommand(128);
}
但是,我能否从命令行 (cmd) 访问这些自定义命令,就像我可以访问这些自定义命令一样 start/stop/... 服务?
编辑:(无需创建中间件应用程序来处理服务,只需使用标准工具)
您可以使用服务控制命令行工具sc
> sc control MyWindowsService 128
(在后台一切都使用 Win32 的 ControlService
API。)
我已经实现了一个 Windows 服务,其中包含覆盖 OnCustomCommand 方法的自定义命令。
我可以从另一个 .net 应用程序访问这些自定义命令:
ServiceController Controller = new ServiceController("MyWindowsService");
if (Controller.Status == ServiceControllerStatus.Running)
{
Controller.ExecuteCommand(128);
}
但是,我能否从命令行 (cmd) 访问这些自定义命令,就像我可以访问这些自定义命令一样 start/stop/... 服务?
编辑:(无需创建中间件应用程序来处理服务,只需使用标准工具)
您可以使用服务控制命令行工具sc
> sc control MyWindowsService 128
(在后台一切都使用 Win32 的 ControlService
API。)