|
//Create a non-visual object uf_get_exename
//Declare local external function(api)
Function Long CreateToolhelp32Snapshot(Long Flags,Long ProcessId) Library "kernel32.dll"
Function Integer Process32First(uLong Snapshot,ref s_Process Process) Library "kernel32.dll"
Function Integer Process32Next(uLong Snapshot,ref s_Process Process) Library "kernel32.dll"
//Create structure before declaration
unsignedlong structsize
unsignedlong usage
unsignedlong processid
unsignedlong defaultheapid
unsignedlong moduleid
unsignedlong threads
unsignedlong parentprocessid
unsignedlong classbase
unsignedlong flags
character filename[260]
//The function of constructing the object uf_get_exename of_getexe()
//////////////////////////of_getexe()//////////////////// ////
Function: enumerate processes and return the PID of the specified process number
Incoming: None
Back: Long
///////////////////////////////////////////////// ///////////
s_Process lst_Process
string ls_filename[100] ,ls_curexename
ulong ln_ProcessID,ln_SameCount,ln_Snapshot,ln_Circle,ln_Count,ul_PID
ul_PID = 0
ln_Snapshot = CreateToolhelp32Snapshot(2,0)
if (ln_Snapshot<1) then return 0
lst_Process.StructSize = 296
if Process32First(ln_Snapshot,lst_Process)=0 then return 0
//Enumerate processes under current permissions
debugbreak()
do while true
if Process32Next(ln_Snapshot,lst_Process)=0 then exit
ln_Count = ln_Count + 1
ls_FileName[ln_Count] = lst_Process.FileName
If Lower(ls_FileName[ln_Count]) ='iexplore.exe' Then
//Get the process number
ul_PID = lst_Process.ProcessID
//messagebox(string(ul_PID),ls_FileName[ln_Count])
End If
loop
return ul_PID
//Next
//Create a form, put a button on it cb_click
//Declare local external function(api) in the form
FUNCTION ulong TerminateProcess(ulong hProcess,ulong uExitCode) LIBRARY "kernel32.dll"
FUNCTION ulong OpenProcess(ulong dwDesiredAccess,ulong bInheritHandle,ulong dwProcessId) LIBRARY "kernel32.dll"
//cb_click clicked event
uf_get_exename luf_get_exename
INTEGER li_rc
ULONG ul_PID
ULONG PROCESS_TERMINATE = 0001
ULONG hwdprocess
If messagebox('End process','Are you sure? Kill?',question!,yesno!,1) = 2 Then return
//Create instance variables
luf_get_exename = create uf_get_exename
//Get the specified process number
ul_PID = luf_get_exename.of_getexe()
If ul_PID = 0 Then
Messagebox('End process','No IE process found!')
return
End If
If ul_PID <> 0 Then
//Get the process handle of the specified process number
hwdprocess = OpenProcess(PROCESS_TERMINATE,1,ul_PID)
//messagebox('',string(hwdprocess))
//End the process, return non-zero successfully
li_rc = TerminateProcess(hwdprocess,0)
If li_rc <> 0 Then Messagebox('End process','Successfully end process!')
End If
Destroy luf_get_exename; |
|