ChangeServiceConfig2() private method

private ChangeServiceConfig2 ( IntPtr hService, SERVICE_CONFIG_INFOLEVEL dwInfoLevel, IntPtr lpInfo ) : bool
hService System.IntPtr
dwInfoLevel SERVICE_CONFIG_INFOLEVEL
lpInfo System.IntPtr
return bool
Ejemplo n.º 1
0
        public void ChangeConfig(TimeSpan failureResetPeriod, List <SC_ACTION> actions)
        {
            SERVICE_FAILURE_ACTIONS sfa = new SERVICE_FAILURE_ACTIONS
            {
                dwResetPeriod = (int)failureResetPeriod.TotalSeconds,
                lpRebootMsg   = "",
                lpCommand     = ""
            };
            // delete message
            // delete the command to run

            int len = Marshal.SizeOf(typeof(SC_ACTION));

            sfa.cActions    = actions.Count;
            sfa.lpsaActions = Marshal.AllocHGlobal(len * actions.Count);
            try
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    Marshal.StructureToPtr(actions[i], new IntPtr(sfa.lpsaActions.ToInt64() + i * len), false);
                }

                if (!Advapi32.ChangeServiceConfig2(Handle, SERVICE_CONFIG_INFOLEVEL.SERVICE_CONFIG_FAILURE_ACTIONS, ref sfa))
                {
                    throw new Exception("Failed to change the failure actions", new Win32Exception());
                }
            }
            finally
            {
                Marshal.FreeHGlobal(sfa.lpsaActions);
            }
        }
Ejemplo n.º 2
0
        /// <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());
            }
        }
Ejemplo n.º 3
0
 public void SetDescription(string description)
 {
     _ = Advapi32.ChangeServiceConfig2(Handle, SERVICE_CONFIG_INFOLEVEL.SERVICE_CONFIG_DESCRIPTION, new SERVICE_DESCRIPTION {
         lpDescription = description
     });
 }