2017-11-27 18:50:18 -05:00
|
|
|
|
#if !NETSTANDARD2_0
|
|
|
|
|
using System.ComponentModel;
|
2017-11-27 13:11:20 -05:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
using static Vanara.PInvoke.AdvApi32;
|
|
|
|
|
|
|
|
|
|
namespace Vanara.Extensions
|
|
|
|
|
{
|
2018-04-05 16:17:33 -04:00
|
|
|
|
/// <summary>Extension methods for <see cref="ServiceController"/>.</summary>
|
2017-11-27 13:11:20 -05:00
|
|
|
|
public static partial class ServiceControllerExtension
|
|
|
|
|
{
|
|
|
|
|
public static void SetStartType(this ServiceController svc, ServiceStartMode mode)
|
|
|
|
|
{
|
|
|
|
|
using (var serviceHandle = svc.ServiceHandle)
|
|
|
|
|
{
|
|
|
|
|
if (!ChangeServiceConfig(serviceHandle.DangerousGetHandle(), ServiceTypes.SERVICE_NO_CHANGE, (ServiceStartType)mode, ServiceErrorControlType.SERVICE_NO_CHANGE))
|
|
|
|
|
throw new ExternalException("Could not change service start type.", new Win32Exception());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-27 18:50:18 -05:00
|
|
|
|
#endif
|