#include <windows.h>
int main(int argc, char* argv[])
{
HWND hwnd = FindWindow(NULL,"无标题 - 记事本");
if (hwnd != NULL)
{
SendMessage(hwnd,WM_CLOSE,0,0);
printf("程序已经关闭!\n");
}else{
printf("未发现要关闭的应用程序!\n");
}
return 0;
}
#include <windows.h>
#include <stdio.h>
//#include <winbase.h>
BOOL TernimateProcessById(DWORD dwProcessId){
BOOL bRet=FALSE;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessId);
if (hProcess != NULL)
{
bRet = TerminateProcess(hProcess,0);
}
CloseHandle(hProcess);
return bRet;
}
int main(int argc , char *argv[]){
BOOL bRet = TernimateProcessById(3092);
if (!bRet)
{
printf("关闭进程出错\n");
}else{
printf("关闭进程成功\n");
}
return 0;
}