Analysis-Services/AlmToolkit/BismNormalizer/TabularCompare/DesktopInstances/ProcessExtensions.cs
2023-09-28 08:08:39 -07:00

33 lines
915 B
C#

using System.Diagnostics;
using System.Linq;
using System.Management;
//namespace DaxStudio.UI.Extensions
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
{
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;
}
}
}
}