/// <summary> /// Sets the DelayedAutoStart flag. /// It will be applioed to services with Automatic startup mode only. /// If the platform does not support this flag, an exception may be thrown. /// </summary> /// <param name="enabled">Value to set</param> /// <exception cref="Exception">Operation failure, e.g. the OS does not support this flag</exception> public void SetDelayedAutoStart(bool enabled) { SERVICE_DELAYED_AUTO_START settings = new SERVICE_DELAYED_AUTO_START { fDelayedAutostart = enabled }; if (!Advapi32.ChangeServiceConfig2(Handle, SERVICE_CONFIG_INFOLEVEL.SERVICE_CONFIG_DELAYED_AUTO_START_INFO, ref settings)) { throw new Exception("Failed to change the DelayedAutoStart setting", new Win32Exception()); } }
internal static extern bool ChangeServiceConfig2(IntPtr hService, SERVICE_CONFIG_INFOLEVEL dwInfoLevel, ref SERVICE_DELAYED_AUTO_START sfa);