Analysis-Services/BismNormalizer/AlmToolkit/ProcessExtensions.cs

32 lines
840 B
C#
Raw Normal View History

2019-11-28 15:51:28 +08:00
using System.Diagnostics;
using System.Linq;
using System.Management;
namespace AlmToolkit
{
public static class ProcessExtensions
{
public static Process GetParent(this Process process)
{
try
{
using (var query = new ManagementObjectSearcher(
"SELECT ParentProcessId " +
"FROM Win32_Process " +
"WHERE ProcessId=" + process.Id))
{
return query
.Get()
.OfType<ManagementObject>()
.Select(p => Process.GetProcessById((int)(uint)p["ParentProcessId"]))
.FirstOrDefault();
}
}
catch
{
return null;
}
}
}
}