VCpp关闭其它进程

⌚Time: 2022-10-07 23:09:27

👨‍💻Author: Jack Ge

关闭记事本为例子


HANDLE hProcessHandle;

ULONG nProcessID;

CWnd *theWindow = NULL;

theWindow = FindWindow(NULL,L"无标题 - 记事本");

if (NULL == theWindow)

{

    return;

}

GetWindowThreadProcessId(theWindow->GetSafeHwnd(),&nProcessID);

hProcessHandle = OpenProcess(PROCESS_TERMINATE,false,nProcessID);

TerminateProcess(hProcessHandle,4);

HANDLE hProcessHandle;

ULONG nProcessID;

HWND hWindow;

hWindow = FindWindow(NULL,L"无标题 - 记事本");

if (NULL != hWindow)

{

    GetWindowThreadProcessId(hWindow,&nProcessID);

    hProcessHandle = OpenProcess(PROCESS_TERMINATE,false,nProcessID);

    TerminateProcess(hProcessHandle,4);

}