Adry3000
asked on
Kill a system process from Visual Basic 6
Hello!
I have this code from another question and it works properly when I try to execute a program or process but I wanna know how to kill it, or kill some process if I knew the name of the .exe.
MODULE1------------------- ---------- ---------- ---------- ----------
Option Explicit
Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function GetTickCount Lib "kernel32" () As Long
Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
-------------------------- ---------- ---------- ---------- ---------- -
FORM1--------------------- ---------- ---------- ---------- ---------- -
Option Explicit
Dim pID&
Dim pHandle&
Public Sub APISleep(interval&)
sT = GetTickCount
Do
DoEvents
pT = GetTickCount
If pT - sT > interval Then
Exit Do
End If
Loop
End Sub
Private Sub Command1_Click()
Dim tmp&
pID = Shell("calc.exe", 1)
pHandle = OpenProcess(&H100000, True, pID)
APISleep 5000
tmp = TerminateProcess(pHandle, 0)
End Sub
Private Sub Command2_Click()
ExitProcess pHandle
End Sub
-------------------------- ---------- ---------- ---------- ---------- -----
The function ExitProcess ends my form1 and VisualBasic and TerminateProcess it doesnt work...
Someone can help me?
I have this code from another question and it works properly when I try to execute a program or process but I wanna know how to kill it, or kill some process if I knew the name of the .exe.
MODULE1-------------------
Option Explicit
Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function GetTickCount Lib "kernel32" () As Long
Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
--------------------------
FORM1---------------------
Option Explicit
Dim pID&
Dim pHandle&
Public Sub APISleep(interval&)
sT = GetTickCount
Do
DoEvents
pT = GetTickCount
If pT - sT > interval Then
Exit Do
End If
Loop
End Sub
Private Sub Command1_Click()
Dim tmp&
pID = Shell("calc.exe", 1)
pHandle = OpenProcess(&H100000, True, pID)
APISleep 5000
tmp = TerminateProcess(pHandle, 0)
End Sub
Private Sub Command2_Click()
ExitProcess pHandle
End Sub
--------------------------
The function ExitProcess ends my form1 and VisualBasic and TerminateProcess it doesnt work...
Someone can help me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Only cut and paste :D
thank you very much!!! you're a crack ;)