Skip to content

Commit

Permalink
Add timeouts to service enable/disable/delete actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Klocman committed Sep 28, 2023
1 parent 0275374 commit 6115328
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/UninstallTools/Startup/Service/ServiceEntryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
}

Expand All @@ -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) });
}
}
}

0 comments on commit 6115328

Please sign in to comment.