gpt4 book ai didi

c# - 来自命令行的 Windows 服务自定义命令

转载 作者:可可西里 更新时间:2023-11-01 11:26:32 24 4
gpt4 key购买 nike

我已经使用覆盖 OnCustomCommand 方法的自定义命令实现了一个 Windows 服务。

我可以从另一个 .net 应用程序访问这些自定义命令:

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

但是,我能否像启动/停止/...服务一样从命令行 (cmd) 访问这些自定义命令?

编辑:(无需创建中间件应用程序来处理服务,只需使用标准工具即可)

最佳答案

您可以使用服务控制命令行工具 sc

> sc control MyWindowsService 128

(在幕后,一切都在使用 Win32 的 ControlService API。)

关于c# - 来自命令行的 Windows 服务自定义命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com