modules/InstallationSDK.ChefClientInstaller/code/WindowsService.cs
/// <summary>
/// Kill process and all spawn. Travers all children for multi generation children.
/// </summary>
/// <param name="parentProcessId">Parent ID</param>
Kill process and all spawn. Travers all children for multi generation children.
Kill process and all spawn . Travers all children for multi generation children .
private void KillSpawnedProcesses(UInt32 parentProcessId)
        {
            Trace.TraceInformation("{0} - Finding processes spawned by process with Id [" + parentProcessId + "]", Name);
            var searcher = new ManagementObjectSearcher(
                "SELECT * " +
                "FROM Win32_Process " +
                "WHERE ParentProcessId=" + parentProcessId);
            var collection = searcher.Get();
            if (collection.Count > 0)
            {
                Trace.TraceInformation("{0} - Killing [{1}] processes spawned by process with Id [{2}].", Name, collection.Count, parentProcessId);
                foreach (var item in collection)
                {
                    var childProcessId = (UInt32)item["ProcessId"];
                    KillSpawnedProcesses(childProcessId);
                    KillProcess(childProcessId);
                }
            }
        }
private void KillSpawnedProcesses ( UInt32 parentProcessId ) { Trace . TraceInformation ( " " + parentProcessId + " " , Name ) ; var searcher = new ManagementObjectSearcher ( " " + " " + " " + parentProcessId ) ; var collection = searcher . Get ( ) ; if ( collection . Count > 0 ) { Trace . TraceInformation ( " " , Name , collection . Count , parentProcessId ) ; foreach ( var item in collection ) { var childProcessId = ( UInt32 ) item [ " " ] ; KillSpawnedProcesses ( childProcessId ) ; KillProcess ( childProcessId ) ; } } }
Kill process and all spawn.
Kill process and all spawn .
parentProcessId
UInt32
None