|
发表于 2020-8-18 15:00:02
|
显示全部楼层
//创建非可视对象uf_get_exename
//声明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"
//声明前先创建结构
unsignedlong structsize
unsignedlong usage
unsignedlong processid
unsignedlong defaultheapid
unsignedlong moduleid
unsignedlong threads
unsignedlong parentprocessid
unsignedlong classbase
unsignedlong flags
character filename[260]
//构造对象uf_get_exename的函数of_getexe()
///////////////////////////of_getexe()////////////////////////
功能:枚举进程并返回指定进程号PID
传入:无
返回: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
//枚举当前权限下的进程
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
//取得进程号
ul_PID = lst_Process.ProcessID
//messagebox(string(ul_PID),ls_FileName[ln_Count])
End If
loop
return ul_PID
//接下来
//创建一个窗体,上面放一按钮cb_click
//在窗体声明local external function(api)
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事件
uf_get_exename luf_get_exename
INTEGER li_rc
ULONG ul_PID
ULONG PROCESS_TERMINATE = 0001
ULONG hwdprocess
If messagebox('结束进程','确定吗?Kill?',question!,yesno!,1) = 2 Then return
//创建实例变量
luf_get_exename = create uf_get_exename
//获取指定进程号
ul_PID = luf_get_exename.of_getexe()
If ul_PID = 0 Then
Messagebox('结束进程','没有发现IE进程!')
return
End If
If ul_PID <> 0 Then
//获取指定进程号的进程句柄
hwdprocess = OpenProcess(PROCESS_TERMINATE,1,ul_PID)
//messagebox('',string(hwdprocess))
//结束进程,成功返回非零
li_rc = TerminateProcess(hwdprocess,0)
If li_rc <> 0 Then Messagebox('结束进程','成功结束进程!')
End If
Destroy luf_get_exename;
|
|