像带过滤器的任务管理器一样查看

View like Task manager with filter

我正在尝试制作一个应用程序,我可以在其中查看进程、路径、用户和描述(如任务管理器详细信息),但我想要一个过滤器从图像路径所在的源代码中搜索例如包含 'Chrome',或者如果您可以帮助我获取任务管理器图像之类的描述并使用此列进行过滤。如果你能帮助我在不使用其他方法的情况下获取进程的用户名,那就太好了。

谢谢。

这是我改进的地方。

DataTable dt = null;
    private void Form1_Load(object sender, EventArgs e)
    {
        var wmiQueryString = "SELECT * FROM Win32_Process";
        //  var wmiQueryString = "SELECT * FROM Win32_ComputerSystem";
        using (var searcher = new ManagementObjectSearcher(wmiQueryString))
        using (var results = searcher.Get())
        {
            var query = from p in Process.GetProcesses()
                        join mo in results.Cast<ManagementObject>()
                        on p.Id equals (int)(uint)mo["ProcessId"]
                        select new
                        {
                            Process = p.ProcessName,
                            Path = (string)mo["ExecutablePath"],
                            CommandLine = (string)mo["CommandLine"],
                            User = GetProcessOwner(p.Id),
                            Description = mo["Description"]
                        };
            dt = ConvertToDataTable(query);
            dataGridView1.DataSource = dt;
        }

    }
    DataTable ConvertToDataTable<TSource>(IEnumerable<TSource> source)
    {
        var props = typeof(TSource).GetProperties();

        var dt = new DataTable();
        dt.Columns.AddRange(
          props.Select(p => new DataColumn(p.Name, p.PropertyType)).ToArray()
        );

        source.ToList().ForEach(
          i => dt.Rows.Add(props.Select(p => p.GetValue(i, null)).ToArray())
        );
        Array a = source.ToArray();
        for (int i = 0; i < a.Length; i++)
        {

            var x = a.GetValue(i);
            //if (true)
            //{
            //    DataRow r = dt.NewRow();
            //    r.
            //}



            a.ToString();
        }

        return dt;
    }

    public string GetProcessOwner(int processId)
    {
        string query = "Select * From Win32_Process Where ProcessID = " + processId; ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection processList = searcher.Get(); foreach (ManagementObject obj in processList)
        {
            string[] argList = new string[] { string.Empty, string.Empty }; int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList)); if (returnVal == 0)
            {
               // return DOMAIN\user 
               return argList[0]; 
            }
        }
        return "NO OWNER";
    }

What I have

TaskManager what I want

进程描述来源于文件描述。你可以这样抢:

private void Form1_Load(object sender, EventArgs e)
{
  var wmiQueryString = "SELECT * FROM Win32_Process";
  //  var wmiQueryString = "SELECT * FROM Win32_ComputerSystem";
  using (var searcher = new ManagementObjectSearcher(wmiQueryString))
  using (var results = searcher.Get())
  {
    var query = from p in Process.GetProcesses()
                join mo in results.Cast<ManagementObject>()
                on p.Id equals (int)(uint)mo["ProcessId"]
                select new
                {
                  Process = p.ProcessName,
                  Path = (string)mo["ExecutablePath"],
                  CommandLine = (string)mo["CommandLine"],
                  User = GetProcessOwner(p.Id),
                  Description = GetDescription((string)mo["ExecutablePath"])
                };
    dt = ConvertToDataTable(query);
    dataGridView1.DataSource = dt;
  }
}

string GetDescription(string executablePath)
{
  if (!File.Exists(executablePath))
  {
    return "No Description";
  }

  return FileVersionInfo.GetVersionInfo(executablePath).FileDescription;
}

您可能需要运行您的程序以管理员身份显示所有进程的详细信息。

为什么要用其他方法获取用户名?