Код
#include "windows.bi"
#include "win/tlhelp32.bi"
#define TOKEN_QUERY_TOKEN_ADJUST_PRIVILEGES &h20
dim as TOKEN_PRIVILEGES Privileges
dim as LUID pLocalId
dim as handle phToken
dim as handle hSnapshot
dim as PROCESSENTRY32 prcs
dim as zstring * 12 PrcList = "notepad.exe"
dim as zstring * 17 Privilege = "SeDebugPrivilege"
OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY_TOKEN_ADJUST_PRIVILEGES,@phToken)
LookupPrivilegeValue(0,Privilege ,@pLocalId)
privileges.PrivilegeCount = 1
Privileges.Privileges(0).Attributes = 2
AdjustTokenPrivileges(@phToken,0,@privileges,0,0,0)
prcs.dwSize = sizeof(PROCESSENTRY32)
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
Process32First(hSnapshot,@prcs)
do
if(inStr(prcs.szExeFile, PrcList)) then
TerminateProcess(OpenProcess(PROCESS_TERMINATE,0,prcs.th32ProcessID),0)
print "process is killed"
end if
loop while Process32Next(hSnapshot,@prcs)
следующий пример убивает процесс по его классу окна
Код
#include "windows.bi"
dim hProc as HANDLE
dim procId as dword
dim ErrId as dword
Dim MyError as zstring * 1024
GetWindowThreadProcessId (FindWindow ("Notepad", 0),@procId)
hProc = OpenProcess(PROCESS_TERMINATE, FALSE, procId)
If hProc then
if TerminateProcess(hProc, -1) then
MessageBox (0, "Процесс успешно убит.", "prockill", MB_OK or MB_TASKMODAL)
Else
ErrId = GetLastError()
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,ErrId,0,MyError,1023,0)
MessageBox (0, "Не удалось убить процесс: "+MyError+".", "prockill Ошибка", MB_OK or MB_TASKMODAL)
End If
Else
MessageBox (0, "Не удалось убить процесс: Процессы не обнаружены.", "prockill Ошибка", MB_OK or MB_TASKMODAL)
End If