[英]Get list of all processes windows name
I am currently using the following code to get the processID of every process running.我目前正在使用以下代码来获取每个正在运行的进程的 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;
}
I would also like to get the Window title to each of these processes if they have one.我还想获得每个进程的 Window 标题(如果有的话)。 I am only interested in the process in my current session so I will filter out all processes based on session ID.
我只对我当前session中的进程感兴趣,所以我会根据session ID过滤掉所有进程。 If they are my session then I would like to get the Window Title.
如果他们是我的 session 那么我想获得 Window 标题。
So for example, if I ran this code with 10 notepads open I would see例如,如果我在打开 10 个记事本的情况下运行这段代码,我会看到
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
...
But I want to get the title so that I know which notepad has which file open.但我想获得标题,以便我知道哪个记事本打开了哪个文件。
Something like: Get hwnd by process id c++类似于: 通过进程 ID c++ 获取 hwnd
HWND g_HWND=NULL;
BOOL CALLBACK EnumWindowsProcMy(HWND hwnd,LPARAM lParam)
{
DWORD lpdwProcessId;
GetWindowThreadProcessId(hwnd,&lpdwProcessId);
if(lpdwProcessId==lParam)
{
g_HWND=hwnd;
return FALSE;
}
return TRUE;
}
EnumWindows(EnumWindowsProcMy,m_ProcessId);
Then you have to call:然后你必须打电话:
GetWindowText(g_hwnd, title, nMax);
int GetWindowTextA(
HWND hWnd,
LPSTR lpString,
int nMaxCount
);
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtexta https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtexta
With the WINDOWTITLE parameter and a wildcard * (or what's needed)使用 WINDOWTITLE 参数和通配符 *(或需要什么)
How to get the window title of running application with command-line? 如何使用命令行获取运行应用程序的 window 标题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.