![](/img/trans.png)
[英]How To get the full name of all processes running including kernel processes on windows
[英]Get list of all processes windows name
我目前正在使用以下代碼來獲取每個正在運行的進程的 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;
}
我還想獲得每個進程的 Window 標題(如果有的話)。 我只對我當前session中的進程感興趣,所以我會根據session ID過濾掉所有進程。 如果他們是我的 session 那么我想獲得 Window 標題。
例如,如果我在打開 10 個記事本的情況下運行這段代碼,我會看到
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
...
但我想獲得標題,以便我知道哪個記事本打開了哪個文件。
類似於: 通過進程 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);
然后你必須打電話:
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
使用 WINDOWTITLE 參數和通配符 *(或需要什么)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.