#include <stdio.h>
#include <iostream>
#include <windows.h>
#include <Urlmon.h>
using namespace std;
int main()
{
//创建记事本进程
/*PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
int bRet = CreateProcess("c:\windows\system32\notepad.exe",
NULL,
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si,
&pi);
if( !bRet)
{
cout<<"CreateProcess Error!"<<endl;
return -1;
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;*/
//结束记事本进程
HWND hNoteWnd = FindWindow(NULL,"无标题 - 记事本");
if( hNoteWnd == NULL)
{
return -1;
}
DWORD dwNotePid = 0;
GetWindowThreadProcessId(hNoteWnd,&dwNotePid);
if( dwNotePid == 0)
{
return -1;
}
HANDLE hNoteHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwNotePid);
if( hNoteHandle == NULL)
{
return -1;
}
TerminateProcess(hNoteHandle,0);
CloseHandle(hNoteHandle);
return 0;
}
#include <iostream>
#include <windows.h>
#include <Urlmon.h>
using namespace std;
int main()
{
//创建记事本进程
/*PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
int bRet = CreateProcess("c:\windows\system32\notepad.exe",
NULL,
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si,
&pi);
if( !bRet)
{
cout<<"CreateProcess Error!"<<endl;
return -1;
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;*/
//结束记事本进程
HWND hNoteWnd = FindWindow(NULL,"无标题 - 记事本");
if( hNoteWnd == NULL)
{
return -1;
}
DWORD dwNotePid = 0;
GetWindowThreadProcessId(hNoteWnd,&dwNotePid);
if( dwNotePid == 0)
{
return -1;
}
HANDLE hNoteHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwNotePid);
if( hNoteHandle == NULL)
{
return -1;
}
TerminateProcess(hNoteHandle,0);
CloseHandle(hNoteHandle);
return 0;
}