Killing a process using TerminateProcess, CloseHandle and OpenProcess 
Author Message
 Killing a process using TerminateProcess, CloseHandle and OpenProcess

Hi all,
    I saw an article, how to Kill a running process.
    I use the following Syntax:
____________SNIP_______________
hInstance = Shell("dos app")
hProcessID = OpenProces (PROCESS_ALL_ACCESS,0,hInstance)
lRetval = TerminateProcess(hProcessID, 0)
lRetval = CloseHandle hProcessID
lRetval = CloseHandle hInstance
____________SNIP_______________
So. I heard about this in a newsgroup and pasted this code into my Project.
I declared the Functions as shown down, but it won't work.
______________SNIP______________________
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hprocess as
long, ByVal uExitCode as long) as boolean

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject as long)
as boolean

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
as string, ByVal dwProcessID as string, ByVal ProcessID as boolean) as long
______________SNIP______________________
    So. I hope anybody can help me. I think the cause is, that in the MSDN
Library, the functions are declared for example as DWord or sth. else. Not
as the standart declaration methods (Boolean, Integer, Long, and so on...)

Regards,
    Freddy



Sat, 08 Sep 2001 03:00:00 GMT  
 Killing a process using TerminateProcess, CloseHandle and OpenProcess
Freddy,
You show

Quote:
>Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
>as string, ByVal dwProcessID as string, ByVal ProcessID as boolean) as long

which is wrong, it should be LONG for all parameters.

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
as Long, ByVal dwProcessID as Long, ByVal ProcessID as Long) as long

Give that a try.
--
Karl Westberg, MCP



Sun, 09 Sep 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Killing a process using TerminateProcess, CloseHandle and OpenProcess

2. Killing a process using TerminateProcess, CloseHandle and OpenProcess

3. Killing a process using TerminateProcess, CloseHandle and OpenProcess

4. Killing a process using TerminateProcess, CloseHandle and OpenProcess

5. OpenProcess() / TerminateProcess() woes

6. Killing a process in NT (without using WMI)

7. Need Help with killing a process using VBScript

8. Killing a Process using VBScript

9. !HELP - Listing and killing processes and programs using VB

10. How to kill a process on a remote NT server (without using rkill.exe)

11. PSAPI.dll - OpenProcess - Unable to get process handle fo r some p rocesses

12. PSAPI.dll - OpenProcess - Unable to get process handle for some p rocesses

 

 
Powered by phpBB® Forum Software