简体   繁体   English

获取所有进程的列表 windows 名称

[英]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.但我想获得标题,以便我知道哪个记事本打开了哪个文件。

1) HWND 1)HWND

2) Tasklist (call a system command and take the output) 2)任务列表(调用系统命令并获取输出)

  1. You can find the HWND of the windows (one process may have many windows though) and then GetWindowText(hwnd).您可以找到 windows 的 HWND(尽管一个进程可能有多个 windows),然后是 GetWindowText(hwnd)。

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

2) Tasklist 2) 任务清单

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM