modules/InstallationSDK.ChefClientInstaller/code/WindowsService.cs
/// <summary>
/// Stop the Windows Service, if Terminate on Failure, then terminate process and all child spawn.
/// </summary>
Stop the Windows Service, if Terminate on Failure, then terminate process and all child spawn.
Stop the Windows Service if Terminate on Failure then terminate process and all child spawn .
public void Stop()
        {
            try
            {
                Trace.TraceInformation("{0} - attempting to stop the {0} windows service.", Name);
                using (var chefService = new ServiceController(Name))
                {
                    if (chefService != null && chefService.Status != ServiceControllerStatus.Stopped)
                    {
                        chefService.Stop();
                        chefService.WaitForStatus(ServiceControllerStatus.Stopped, TimeToWait);
                        Trace.TraceInformation("{0} - {0} windows service Stopped.", Name);
                    }
                    else
                    {
                        Trace.TraceInformation("{0} - {0} windows service is not running.", Name);
                    }
                }
            }
            catch (System.ServiceProcess.TimeoutException)
            {
                Trace.TraceInformation("{0} - failed to stop {0} in time allotted [{1}].", Name, TimeToWait);
                if (TerminateOnFailure)
                {
                    Trace.TraceInformation("{0} - attempting to terminate service process and its children.", Name);
                    KillService();
                }
            }
            catch (InvalidOperationException e)
            {
                Trace.TraceInformation("{0} - Invalid Operation, is the role running with elevated privileges. Ex:{1}.", Name, e.ToString());
            }
        }
public void Stop ( ) { try { Trace . TraceInformation ( " " , Name ) ; using ( var chefService = new ServiceController ( Name ) ) { if ( chefService != null && chefService . Status != ServiceControllerStatus . Stopped ) { chefService . Stop ( ) ; chefService . WaitForStatus ( ServiceControllerStatus . Stopped , TimeToWait ) ; Trace . TraceInformation ( " " , Name ) ; } else { Trace . TraceInformation ( " " , Name ) ; } } } catch ( System . ServiceProcess . TimeoutException ) { Trace . TraceInformation ( " " , Name , TimeToWait ) ; if ( TerminateOnFailure ) { Trace . TraceInformation ( " " , Name ) ; KillService ( ) ; } } catch ( InvalidOperationException e ) { Trace . TraceInformation ( " " , Name , e . ToString ( ) ) ; } }
Stop the Windows Service, if Terminate on Failure, then terminate process and all child spawn.
Stop the Windows Service if Terminate on Failure then terminate process and all child spawn .
// Stop Chef Client 