
是從 ce shell 抄一些出來
不過沒試過 應該還需要修一下才 build 的過
不然就是裝個 eVC or PB 然後用 Remote Process Viewer 來 kill
#include <windows.h>
#include "shellapi.h"
#include "shell.h"
#define KEEP_SYSCALLS
#include <kernel.h>
#include <celog.h>
#include <windev.h>
#include <strsafe.h>
#include "lmemdebug.h"
//*** IsPatMatch -- does text match the pattern arg?
// NOTES
// no REs for now (ever?), so the Is'Pat'Match is a slight misnomer
BOOL IsPatMatch(TCHAR *pszPat, TCHAR *pszText)
{
BOOL fRet;
TCHAR szText[64]; // 64 is plenty big enough
if (!pszPat)
return TRUE;
_tcsncpy(szText, pszText, ARRAYSIZE(szText) - 1);
szText[ARRAYSIZE(szText) - 1] = 0;
_tcslwr(szText);
fRet = _tcsstr(szText, pszPat) != NULL;
return fRet;
}
DWORD
GetIdFromName(
PTSTR szName
)
{
HANDLE hSnap;
PROCESSENTRY32 proc;
DWORD dwRet = 0;
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPNOHEAPS ,0);
if (INVALID_HANDLE_VALUE != hSnap) {
proc.dwSize = sizeof(proc);
if (Process32First(hSnap,&proc)) {
dwRet = 0;
do {
if (IsPatMatch(szName, proc.szExeFile)) {
dwRet = proc.th32ProcessID;
break;
}
} while (Process32Next(hSnap,&proc));
}
CloseToolhelp32Snapshot(hSnap);
}
return dwRet;
}
BOOL DoKillProc (PTSTR szProcName) {
DWORD dwProcID = 0;
DWORD oldPerm;
dwProcId = GetIdFromName(szProcName);
if (dwProcID)
{
FmtPuts(TEXT("Attempting to kill process of handle x ..."), dwProcID);
oldPerm = SetProcPermissions((DWORD)-1);
if (TerminateProcess((HANDLE)dwProcID,0))
{
Puts(TEXT("Succeeded
"));
}
else
{
Puts(TEXT("Failed
"));
}
SetProcPermissions(oldPerm);
}
else
{
Puts(TEXT("Invalid <pid>, use 'gi proc' first
"));
}
return TRUE;
}
內文搜尋

X