|
-
Aug 4th, 2000, 11:36 PM
#1
Thread Starter
Fanatic Member
The title says it all. What API is equivalent to End Task button in Task Manager?
Chemically Formulated As:
Dr. Nitro
-
Aug 6th, 2000, 06:40 PM
#2
Fanatic Member
Hi Nitro, long time.....
I'm not sure at all just stabbing in the dark, but maybe the API call CloseHandle or CloseWindow could be used, i'll try it and let you know
DocZaf
{;->
[Edited by Zaf Khan on 08-06-2000 at 07:43 PM]
-
Aug 6th, 2000, 06:50 PM
#3
Frenzied Member
sorry to break in. Just wanted to keep updated on the answer to this one.
Thanks
-
Aug 6th, 2000, 07:24 PM
#4
Frenzied Member
I'm Pretty sure it's the Terminate Process API, I'll check MSDN.
Yes it is. You have to use the GetExitCodeProcess API to get an Exit Code
GetExitCodeProcess takes a byref Long as it's second Parameter. For Example
Code:
Dim hWnd As Long
Dim hProcess As Long
Dim lngExitCode As Long
Dim lngProcessId As Long
'Pretend hWnd is already a Window in the Process You want to close
'Get Process ID
Call GetWindowThreadProcess(hWnd, lngProcessID)
'Get Process Handle
hProcess = OpenProcess(PROCESS_TERMINATE,0,lngProcessID)
'Get Exit Code
Call GetExitCodeProcess(hProcess,lngExitCode)
'Terminate Process
Call ExitProcess(hProcess, lngExitCode)
'Close The Process Handle
Call CloseHandle(hProcess)
And You Need the Folowing Declarations
Code:
Private Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" Alias "GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Long) As Long
Const PROCESS_TERMINATE = 1
I'm pretty sure that'll all work
-
Aug 6th, 2000, 11:47 PM
#5
Sam Finch is correct Nitro.
As I showed the link to an example and told you a little before in this thread.
TerminateProcess would be equivalent to the End Task Button in the Ctrl Alt Del area.
And I also gave you the link to a good program (source code included) which showed you how to use the TerminateProcess Api.
As you probably noticed, when you End Task, you have to do it a few times or wait a minute or two.
With TerminateProcess, it closes the app right away, no waiting or another popup asking you to End Task or Cancel.
It is probably the same except Windows takes longer to react/respond. Either way, both of them do the same thing: kill the application.
[Edited by Matthew Gates on 08-07-2000 at 12:49 AM]
-
Aug 7th, 2000, 02:10 PM
#6
Thread Starter
Fanatic Member
Thank You Gentlemen!
Zaf
Thanks! Long time no talk to!
Wengang
Sam's code works!
Mr. Sam
Thanks again. I was researching on this but didn't know how to get it working. Matthew gave me a pretty good idea for a start. You spelled some words wrong in your code so I hope you don't mind I respell it. I still kept your logic. Again, thanks Sam.
Matthew
Thanks for the detail instruction on both thread Matthew. That is new information to me that Terminate API is better than END TASK button. Thanks. I did try out the example that you posted. However, that file did not work on Window 2k because of the RegisterServiceProcess API. That is why I didn't get around to it. I try commenting out that API but than it did nothing to the window I was trying to close.
How long have you been on this site? Out of know where, you stormed in. That is a compliment by the way. Thanks!
This is Sam's code. Paste this into a form and compile it into an EXE.
Code:
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Const PROCESS_TERMINATE = 1
Private Sub Form_Click()
Dim hProcess As Long
Dim lngExitCode As Long
Dim lngProcessId As Long
'Get Process ID
Call GetWindowThreadProcessId(Me.hwnd, lngProcessId)
'Get Process Handle
hProcess = OpenProcess(PROCESS_TERMINATE, 0, lngProcessId)
'Get Exit Code
Call GetExitCodeProcess(hProcess, lngExitCode)
'Terminate Process
Call TerminateProcess(hProcess, lngExitCode)
'Close The Process Handle
Call CloseHandle(hProcess)
End Sub
Chemically Formulated As:
Dr. Nitro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|