获取用户会话下的进程列表 [英] Get the list of process under a user session
本文介绍了获取用户会话下的进程列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计们,
我正在尝试获取在用户会话上运行的所有进程的列表。
在Windows 2008 SP2中测试相同时,使用非管理员用户,我可以发现下面的代码获取属于管理员用户的所有进程。
有没有办法获得仅在该用户上运行的进程列表(非管理员)?
请在下面找到以下代码段:
Hi folks,
I'm trying to get the list of all processes which are running on a user session.
While testing the same in Windows 2008 SP2, with a non-admin user, I could find that the below piece of code fetches all the process which belongs to the admin user.
Is there a way to get the list of process which are running only on that user (non-admin)?
Please find the code snippet below:
DWORD procID = 0;
FILE *fp;
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if ( processesSnapshot == INVALID_HANDLE_VALUE )
{
return;
}
fp = _tfopen(_T("C:\\Process_List.txt") , _T("a+") );
if (fp == NULL) {
MessageBox(_T("Can't open File"));
return;
}
Process32First(processesSnapshot, &processInfo);
_ftprintf(fp, _T("\n Process: %s :: Process ID: %d"), processInfo.szExeFile, processInfo.th32ProcessID);
procID = processInfo.th32ProcessID;
if (procID == 0)
{
while ( Process32Next(processesSnapshot, &processInfo) )
{
_ftprintf(fp, _T("\n Process: %s :: Process ID: %d"), processInfo.szExeFile, processInfo.th32ProcessID);
}
}
fclose(fp);
CloseHandle(processesSnapshot);
在此先感谢。
问候,
Rajesh
Thanks In Advance.
regards,
Rajesh
推荐答案
你可能需要遍历它们并过滤掉你想要使用的那些。
You'll likely have to walk through them all and filter for the ones you want to work with.
这篇关于获取用户会话下的进程列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文