Esempio n. 1
0
 private static WardenProcess BuildTreeById(int pId, List <ProcessFilter> filters)
 {
     try
     {
         Process process = null;
         try
         {
             process = Process.GetProcessById(pId);
         }
         catch
         {
             process = Process.GetProcesses().FirstOrDefault(it => it.Id == pId);
         }
         var processName = process.ProcessName;
         var processId   = process.Id;
         var path        = GetProcessPath(processId);
         var state       = process.HasExited ? ProcessState.Dead : ProcessState.Alive;
         var arguments   = GetCommandLine(processId);
         var type        = IsWindowsApp(path) ? ProcessTypes.Uwp : ProcessTypes.Win32;
         var warden      = new WardenProcess(processName, processId, path, state, arguments, type, filters);
         var children    = GetChildProcesses(pId);
         foreach (var child in children)
         {
             warden.AddChild(BuildTreeById(child.Id, filters));
         }
         return(new WardenProcess(processName, processId, path, state, arguments, type, filters));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 2
0
 private static WardenProcess BuildTreeById(int pId)
 {
     try
     {
         var process     = Process.GetProcessById(pId);
         var processName = process.ProcessName;
         var processId   = process.Id;
         var path        = ProcessUtils.GetProcessPath(processId);
         var state       = process.HasExited ? ProcessState.Dead : ProcessState.Alive;
         var arguments   = ProcessUtils.GetCommandLine(processId);
         var type        = ProcessUtils.IsWindowsApp(path) ? ProcessTypes.Uwp : ProcessTypes.Win32;
         var warden      = new WardenProcess(processName, processId, path, state, arguments, type);
         var children    = ProcessUtils.GetChildProcesses(pId);
         foreach (var child in children)
         {
             warden.AddChild(BuildTreeById(child.Id));
         }
         return(new WardenProcess(processName, processId, path, state, arguments, type));
     }
     catch (Exception)
     {
         return(null);
     }
 }