kill a process from visual basic 
Author Message
 kill a process from visual basic

Hi.
Do anyone know how can I kill a process from Visual Basic application?
I want clear my task manager from the winword process.
Thanks, Alex


Tue, 31 May 2005 23:08:54 GMT  
 kill a process from visual basic
Hello, you can kill a proccess easily from vb with the code below. Hopefully it
helps.

Public Declare Function GetWindowThreadProcessId Lib "user32" Alias
"GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" Alias
"TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As
Long) As Long

Public Sub KillProcess(hWnd As Long)
    Dim pId As Long
    Call GetWindowThreadProcessId(hWnd, pId)
    Call TerminateProcess(OpenProcess(&H1F0FFF, 0&, pId), 0&)
End Sub

(you can get the window handle by using the findwindow api call)

Enjoy.
-c/c



Wed, 01 Jun 2005 00:36:24 GMT  
 kill a process from visual basic

Quote:

>Hello, you can kill a proccess easily from vb with the code below. Hopefully it
>helps.

>Public Declare Function GetWindowThreadProcessId Lib "user32" Alias
>"GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
>Public Declare Function TerminateProcess Lib "kernel32" Alias
>"TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
>Public Declare Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal
>dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As
>Long) As Long

>Public Sub KillProcess(hWnd As Long)
>    Dim pId As Long
>    Call GetWindowThreadProcessId(hWnd, pId)
>    Call TerminateProcess(OpenProcess(&H1F0FFF, 0&, pId), 0&)
>End Sub

>(you can get the window handle by using the findwindow api call)

Note, that is a spot on reply to the question. It will *kill* your
application by shooting it in the back of the head. It won't be abe to
save or maybe even clean up properly.
If you want to be nice, you could start off sending a WM_CLOSE with
Sendmessage , even a WM_SYSCOMMAND with wparam as SC_CLOSE and if
those fail then get real {*filter*} with TerminateProcess.

--
Regards, Frank



Wed, 01 Jun 2005 01:20:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Visual Basic 5: Kill process

2. !HELP - Listing and Killing processes and programs in Visual Basic

3. Killing a process and all its children processes....

4. Visual Basic 6 Development Environment - Thread killed on compiling

5. Start and kill an application behind Visual Basic

6. How to kill a Thread in Visual Basic??

7. Visual Basic 5 service pack...killed my VB5 enterprise

8. Tracking other processes with Visual Basic

9. Visual Basic and image processing

10. Visual Basic and image processing

11. How detect idle of other process with API and Visual basic

12. NT Task Manager process list from Visual Basic ?

 

 
Powered by phpBB® Forum Software