http://www.codeguru.com/system/PList.html single interface to enumerate processesto terminate a process, use The TerminateProcess function terminates the specified process and all of its threads. BOOL TerminateProcess( HANDLE hProcess, UINT uExitCode );You can send WM_CLOSE message to that program first, if it does not exit, then call TerminateProcess.
single interface to enumerate processesto terminate a process, use The TerminateProcess function terminates the specified process and all of its threads.
BOOL TerminateProcess(
HANDLE hProcess,
UINT uExitCode
);You can send WM_CLOSE message to that program first, if it does not exit, then call TerminateProcess.
// 需要psapi.lib#include "psapi.h"
HANDLE hProcess[256];
int ListNum;
DWORD i;
DWORD ListTbl[256];
DWORD ListSize=256;EnumProcesses(ListTbl,256*sizeof(DWORD),&ListSize);
ListNum=ListSize/sizeof(DWORD);
for(i=0;i<ListNum;i++)
{
hProcess[ProcessNum]=OpenProcess(
ROCESS_QUERY_INFORMATION |PROCESS_VM_READ,FALSE,ListTbl[i]);
if ( hProcess[ProcessNum] )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess[ProcessNum],
&hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleBaseName( hProcess[ProcessNum], hMod,
Info, 256 );
SendDlgItemMessage(hWnd,IDC_PROCESSLIST,LB_ADDSTRING,
0,(LPARAM)Info);
}
CloseHandle(hProcess[ProcessNum]);
}
}
这个通用于任何Windows平台。