1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
// KillProcess.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "KillProcess.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
return 1;
}
// TODO: code your application's behavior here.
if(argc<2)
{
cout << _T("KillProcess utilisation: KillProcess Nom de la fenetre") << endl;
return 0;
}
CString strWindowName=GetCommandLine();
int nPos=strWindowName.ReverseFind('"');
strWindowName=strWindowName.Mid(nPos+2);
cout << _T("Recherche Fenetre:") << (LPCSTR) strWindowName ;
HWND hWnd=FindWindow(NULL,strWindowName);
cout << _T(" :") << (hWnd?_T("Trouvee !!"):_T("Non Trouvee!!")) << endl;
if(!hWnd) return 0;
CString str;
str.Format(_T("FindWindow: 0x%xh"),hWnd);
cout << (LPCSTR) str << endl;
DWORD dwProcessId;
DWORD hThread = GetWindowThreadProcessId(hWnd,&dwProcessId);
str.Format(_T("GetWindowThreadProcessId: 0x%xh Process 0x%xh"),hThread,dwProcessId);
cout <<(LPCSTR) str << endl;
cout << _T("Envoi PostThreadMessage de WM_QUIT ...") << endl;
PostThreadMessage(hThread,(UINT) WM_QUIT,0,0);
cout << _T("Termine !") << endl;
return nRetCode;
} |
Partager