[파워빌더] API로 읽어서 프로세서 Kill하기.
$PBExportHeader$nvo_kill_process.sru
forward
global type nvo_kill_process from nonvisualobject
end type
type s_process from structure within nvo_kill_process
end type
end forward
type s_process from structure
unsignedlong structsize
unsignedlong usage
unsignedlong processid
unsignedlong defaultheapid
unsignedlong moduleid
unsignedlong threads
unsignedlong parentprocessid
unsignedlong classbase
unsignedlong flags
character filename[200]
end type
global type nvo_kill_process from nonvisualobject autoinstantiate
end type
type prototypes
Function Long GetCurrentProcessId() Library "kernel32.dll"
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"
Function ulong TerminateProcess(long hProcess,ulong uExitCode) LIBRARY "kernel32.dll"
FUNCTION ulong OpenProcess(ulong dwDesiredAccess,ulong bInheritHandle,ulong dwProcessId) LIBRARY "kernel32.dll"
end prototypes
forward prototypes
public function integer of_kill_process (string as_pro)
end prototypes
public function integer of_kill_process (string as_pro);s_Process lst_Process
String ls_FileName[],ls_CurExeName
ulong ln_ProcessID,ln_Snapshot,ln_Circle,ln_Count //,ln_SameCount
string ls_Kill_File
Long ll_PID,ll_PID2
IF as_pro='' OR isnull(as_pro) Then Return 1
ln_ProcessID = GetCurrentProcessId()
if IsNull(ln_ProcessID) or ln_ProcessID<1 then return -1
ln_Snapshot = CreateToolhelp32Snapshot(2,0)
if (ln_Snapshot<1) then return -1
lst_Process.StructSize = 296
if Process32First(ln_Snapshot,lst_Process)=0 then
return -1
End IF
ls_Kill_File = lst_Process.FileName
IF pos(lower(as_pro),lower(ls_Kill_File))>0 Then
ll_pid=Long(lst_process.processid)
ll_pid2 = Long(OpenProcess(1,0,ll_PID))
TerminateProcess(ll_PID2,1) //Kill Process
End IF
if lst_Process.ProcessID=ln_ProcessID then
ls_CurExeName=lst_Process.FileName
END IF
do while true
if Process32Next(ln_Snapshot,lst_Process)=0 then exit
IF lst_Process.ProcessID=ln_ProcessID Then continue
ls_Kill_File = lst_Process.FileName
IF pos(lower(as_pro),lower(ls_Kill_File))>0 Then
ll_pid=Long(lst_process.processid)
ll_pid2 = Long(OpenProcess(1,0,ll_PID))
TerminateProcess(ll_PID2,1) //Kill Process
End IF
loop
Return 1
end function
on nvo_kill_process.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_kill_process.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
forward
global type nvo_kill_process from nonvisualobject
end type
type s_process from structure within nvo_kill_process
end type
end forward
type s_process from structure
unsignedlong structsize
unsignedlong usage
unsignedlong processid
unsignedlong defaultheapid
unsignedlong moduleid
unsignedlong threads
unsignedlong parentprocessid
unsignedlong classbase
unsignedlong flags
character filename[200]
end type
global type nvo_kill_process from nonvisualobject autoinstantiate
end type
type prototypes
Function Long GetCurrentProcessId() Library "kernel32.dll"
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"
Function ulong TerminateProcess(long hProcess,ulong uExitCode) LIBRARY "kernel32.dll"
FUNCTION ulong OpenProcess(ulong dwDesiredAccess,ulong bInheritHandle,ulong dwProcessId) LIBRARY "kernel32.dll"
end prototypes
forward prototypes
public function integer of_kill_process (string as_pro)
end prototypes
public function integer of_kill_process (string as_pro);s_Process lst_Process
String ls_FileName[],ls_CurExeName
ulong ln_ProcessID,ln_Snapshot,ln_Circle,ln_Count //,ln_SameCount
string ls_Kill_File
Long ll_PID,ll_PID2
IF as_pro='' OR isnull(as_pro) Then Return 1
ln_ProcessID = GetCurrentProcessId()
if IsNull(ln_ProcessID) or ln_ProcessID<1 then return -1
ln_Snapshot = CreateToolhelp32Snapshot(2,0)
if (ln_Snapshot<1) then return -1
lst_Process.StructSize = 296
if Process32First(ln_Snapshot,lst_Process)=0 then
return -1
End IF
ls_Kill_File = lst_Process.FileName
IF pos(lower(as_pro),lower(ls_Kill_File))>0 Then
ll_pid=Long(lst_process.processid)
ll_pid2 = Long(OpenProcess(1,0,ll_PID))
TerminateProcess(ll_PID2,1) //Kill Process
End IF
if lst_Process.ProcessID=ln_ProcessID then
ls_CurExeName=lst_Process.FileName
END IF
do while true
if Process32Next(ln_Snapshot,lst_Process)=0 then exit
IF lst_Process.ProcessID=ln_ProcessID Then continue
ls_Kill_File = lst_Process.FileName
IF pos(lower(as_pro),lower(ls_Kill_File))>0 Then
ll_pid=Long(lst_process.processid)
ll_pid2 = Long(OpenProcess(1,0,ll_PID))
TerminateProcess(ll_PID2,1) //Kill Process
End IF
loop
Return 1
end function
on nvo_kill_process.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_kill_process.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on