- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2013-10-14 08:32:57
|
显示全部楼层
这个其实也不难看下面代码
[code=csharp] private void Form1_Load(object sender, EventArgs e)
{
//获取系统中的进程
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process myProcess in myProcesses)
{
string processname = myProcess.ProcessName;
//进程用户名
string username = GetProcessUserName(myProcess.Id);
}
}
//获得进程的用户名
private static string GetProcessUserName(int pID)
{
string result = string.Empty;
SelectQuery query1 = new SelectQuery("Select * from Win32_Process WHERE processID=" + pID);
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(query1);
try
{
foreach (ManagementObject disk in searcher1.Get())
{
ManagementBaseObject inPar = null;
ManagementBaseObject outPar = null;
inPar = disk.GetMethodParameters("GetOwner");
outPar = disk.InvokeMethod("GetOwner", inPar, null);
result = outPar["User"].ToString();
break;
}
}
catch
{
result = "SYSTEM";
}
return result;
}[/code]
需要添加对 System.Management.dll 的引用
[code=csharp] //进程用户名
string username = GetProcessUserName(myProcess.Id);[/code]
这里是获取的进程的用户名,你把系统用户分一下类,根据用户名就能判断出来是不是系统进程了
自己测试下吧
|
|