From da2772c6c4efb3444e4ea69bc1c4eb4f36ece877 Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Wed, 29 Jan 2020 00:00:00 +0800 Subject: [PATCH] Treat ERROR_SERVICE_CANNOT_ACCEPT_CTRL as success for stop command --- src/Core/ServiceWrapper/Main.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index a47f3f4..82bac36 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -728,7 +728,22 @@ namespace winsw if (s is null) ThrowNoSuchService(); - s.StopService(); + try + { + s.StopService(); + } + catch (WmiException e) + { + if (e.ErrorCode == ReturnValue.ServiceCannotAcceptControl) + { + Log.Info($"The service with ID '{descriptor.Id}' is not running"); + } + else + { + throw; + } + } + return; }