Analysis-Services/AlmToolkit/BismNormalizer/TabularCompare/DesktopInstances/ProcessExtensions.cs

33 lines
915 B
C#
Raw Normal View History

2023-09-28 23:08:33 +08:00
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;
}
}
}
}