From 6115328d2b5bc5c5a7a3870d50ca455012a869ff Mon Sep 17 00:00:00 2001 From: Marcin Szeniak <14913904+Klocman@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:54:14 +0200 Subject: [PATCH] Add timeouts to service enable/disable/delete actions --- .../UninstallTools/Startup/Service/ServiceEntryFactory.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/UninstallTools/Startup/Service/ServiceEntryFactory.cs b/source/UninstallTools/Startup/Service/ServiceEntryFactory.cs index 87f29a4f..59b2cdb3 100644 --- a/source/UninstallTools/Startup/Service/ServiceEntryFactory.cs +++ b/source/UninstallTools/Startup/Service/ServiceEntryFactory.cs @@ -87,7 +87,7 @@ public static void EnableService(string serviceName, bool newState) inParams["StartMode"] = newState ? "Automatic" : "Disabled"; // Execute the method and obtain the return values. - var outParams = classInstance.InvokeMethod("ChangeStartMode", inParams, null); + var outParams = classInstance.InvokeMethod("ChangeStartMode", inParams, new InvokeMethodOptions { Timeout = TimeSpan.FromMinutes(1) }); CheckReturnValue(outParams); } @@ -106,7 +106,7 @@ public static void DeleteService(string serviceName) var classInstance = GetServiceObject(serviceName); // Execute the method and obtain the return values. - var outParams = classInstance.InvokeMethod("Delete", null, null); + var outParams = classInstance.InvokeMethod("Delete", null, new InvokeMethodOptions { Timeout = TimeSpan.FromMinutes(1) }); CheckReturnValue(outParams, 16); // 16 - Service Marked For Deletion } @@ -127,7 +127,7 @@ private static void CheckReturnValue(ManagementBaseObject outParams, params UInt private static ManagementObject GetServiceObject(string serviceName) { return new ManagementObject("root\\CIMV2", - $"Win32_Service.Name='{serviceName}'", null); + $"Win32_Service.Name='{serviceName}'", new ObjectGetOptions { Timeout = TimeSpan.FromMinutes(1) }); } } } \ No newline at end of file