コード例 #1
0
        /// <summary>
        /// Stop the service
        /// </summary>
        public void Stop()
        {
            var serviceStatus = new Advapi32.ServiceStatus();

            if (!Advapi32.ControlService(serviceHandle: this, Advapi32.ServiceControl.Stop, ref serviceStatus))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the command. Needs SERVICE_USER_DEFINED_CONTROL right.
        /// </summary>
        /// <param name="command">The command.</param>
        public void ExecuteCommand(int command)
        {
            if (command < 128 || command > 255)
            {
                throw new ArgumentException("Only a range of 128-255 is allowed for custom commands.");
            }

            var serviceStatus = new Advapi32.ServiceStatus();

            Advapi32.ControlService(this, command, ref serviceStatus);
        }