本文介绍了命令行中的Windows服务自定义命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用覆盖OnCustomCommand方法的自定义命令实现了Windows服务。
I've implemented a Windows Service with custom commands overriding OnCustomCommand method.
我可以使用以下方式从另一个.net应用程序访问这些自定义命令:
I can access these custom commands from another .net application with:
ServiceController Controller = new ServiceController("MyWindowsService");
if (Controller.Status == ServiceControllerStatus.Running)
{
Controller.ExecuteCommand(128);
}
但是,我可以从命令行(cmd)访问这些自定义命令吗
But, can I access these custom commands from the command line (cmd) the same way I can start/stop/... the service?
编辑:(无需使用标准工具即可创建中间件应用程序来处理服务)
(Without creating a middleware application to handle the service, just with standard tools)
推荐答案
您可以使用服务控制命令行工具 sc
You can use the Service Control command line tool sc
> sc control MyWindowsService 128
(在后台,所有东西都使用Win32的 ControlService
API。)
(Under the hood everything is using Win32's ControlService
API.)
这篇关于命令行中的Windows服务自定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!