在程序中用RUN运行了一个进程,想结束某个进程,并且希望RUN程序与PB主程序系统工作,请问该调用那个API?谢谢!
------解决方案--------------------
下面是一个用户对象,用于获得进程PID,然后,可以用后面的脚本结束该进程。
$PBExportHeader$uf_get_exename.sru
$PBExportComments$获得进程
forward
global type uf_get_exename from nonvisualobject
end type
type s_process from structure within uf_get_exename
end type
end forward
type s_process from structure
unsignedlong structsize
unsignedlong usage
unsignedlong processid
unsignedlong defaultheapid
unsignedlong moduleid
unsignedlong threads
unsignedlong parentprocessid
unsignedlong calssbase
unsignedlong flags
character filename[260]
end type
global type uf_get_exename from nonvisualobject
end type
global uf_get_exename uf_get_exename
type prototypes
Function Long CreateToolhelp32Snapshot(Long Flags,Long ProcessId) Library "kernel32.dll" alias for "CreateToolhelp32Snapshot;ansi"
Function Integer Process32First(uLong Snapshot,ref s_Process Process) Library "kernel32.dll" alias for "Process32First;ansi"
Function Integer Process32Next(uLong Snapshot,ref s_Process Process) Library "kernel32.dll" alias for "Process32Next;ansi"
end prototypes
forward prototypes
public function long of_getexe (string as_exename)
end prototypes
public function long of_getexe (string as_exename);//构造对象uf_get_exename的函数of_getexe(String as_exename)
///////////////////////////of_getexe(String as_exename)////////////////////////
//功能:枚举进程并返回指定进程号PID
//传入:String as_exename 文件名
//返回: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 //创建快照失败 296是windows决定的
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]) = as_exename Then
//取得进程号
ul_PID = lst_Process.ProcessID
//messagebox(string(ul_PID),ls_FileName[ln_Count])
End If
loop
return ul_PID
end function
on uf_get_exename.create
call super::create
TriggerEvent( this, "constructor" )
end on
on uf_get_exename.destroy