I am currently using the following code to get the processID of every process running.
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. I am only interested in the process in my current session so I will filter out all processes based on session ID. If they are my session then I would like to get the Window Title.
So for example, if I ran this code with 10 notepads open I would see
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++
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
With the WINDOWTITLE parameter and a wildcard * (or what's needed)
How to get the window title of running application with command-line?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.