【发布时间】:2021-01-13 16:03:54
【问题描述】:
我目前正在使用以下代码来获取每个正在运行的进程的 processID。
WTS_PROCESS_INFO* pWPIs = NULL;
DWORD dwProcCount = 0;
if(WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, NULL, 1, &pWPIs, &dwProcCount))
{
//Go through all processes retrieved
for(DWORD i = 0; i < dwProcCount; i++)
{
//pWPIs[i].pProcessName = process file name only, no path!
//pWPIs[i].ProcessId = process ID
//pWPIs[i].SessionId = session ID, if you need to limit it to the logged in user processes
//pWPIs[i].pUserSid = user SID that started the process
}
}
//Free memory
if(pWPIs)
{
WTSFreeMemory(pWPIs);
pWPIs = NULL;
}
我还想获得每个进程的窗口标题(如果它们有的话)。我只对当前会话中的进程感兴趣,因此我将根据会话 ID 过滤掉所有进程。如果他们是我的会话,那么我想获得窗口标题。
例如,如果我在打开 10 个记事本的情况下运行此代码,我会看到
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
...
但我想获取标题,以便知道哪个记事本打开了哪个文件。
【问题讨论】:
-
你是说答案是 EnumWindows 吗?