如何在 WMI 中获取所有用户进程 [英] how to get all the users processes in WMI

查看:65
本文介绍了如何在 WMI 中获取所有用户进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取任务管理器进程(系统、管理员、网络服务和本地服务)中所述的所有用户进程.

i want to get all the user's process as stated in the task manager process's (system, administrator, network service and local service).

我需要通过 WMI 获取它,我找不到每个进程的用户名,我检查了 wmi 进程和任务管理器进程,wmi 仅显示管理员进程.

i need to get it through the WMI, i couldn't find the username of each process and i have checked the wmi process and task manager process, the wmi shows only the administrator process alone.

你能帮我获取所有用户的进程列表吗???

can you help me to get the all user's process list???

推荐答案

您可以浏览Win32_Process 类 获取进程详细信息:

you can browse Win32_Process class to get process details:

using System;
using System.Management;
using System.Windows.Forms;

namespace WMISample
{
    public class MyWMIQuery
    {
        public static void Main()
        {
            try
            {
                ManagementObjectSearcher searcher = 
                    new ManagementObjectSearcher("root\\CIMV2", 
                    "SELECT * FROM Win32_Process"); 

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Win32_Process instance");
                    Console.WriteLine("-----------------------------------");
                    Console.WriteLine("Caption: {0}", queryObj["Caption"]);
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}

或在 c# 中,不使用 WMI :

or in the c#, without using WMI :

Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist)
  {
    Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
  }

这篇关于如何在 WMI 中获取所有用户进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆