[VB6] KillProcess By Window Name

Iniciado por scapula, 6 Noviembre 2011, 07:54 AM

0 Miembros y 1 Visitante están viendo este tema.

scapula

Código (vb) [Seleccionar]
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function TerminateProcess Lib "Kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Function KillProcessByWindowName(Window As String)
 Dim lnghProcess As Long
 Dim lngReturn As Long
 Dim lpProc As Long
 Dim gtWnd As Long

 gtWnd = FindWindow(vbNullString, Window)
 Call GetWindowThreadProcessId(gtWnd, lpProc)
 WindowToProcessId = lpProc
 lnghProcess = OpenProcess(1&, -1&, WindowToProcessId)
 lngReturn = TerminateProcess(lnghProcess, 0&)
End Function

Private Sub Command1_Click()
Call KillProcessByWindowName(App.Title)
End Sub


:P

BlackZeroX

#1
use Option Explicit

Código (vb) [Seleccionar]


Public Function terminateProcessByWindowName(ByRef sName As String) As Boolean
Dim dwProcId    As Long
  Call GetWindowThreadProcessId(FindWindow(vbNullString, sName), dwProcId)
  terminateProcessByWindowName = Not (TerminateProcess(OpenProcess(1&, -1&, dwProcId), 0&) = &H0)
End Function



No es recomendable usar las lineas asi... hay que verificar los retornos y demas cosillas... como por ejemplo si TerminateProcess no se ejecuto o termino erroneamente el APP entonces realizar un CloseHandle...

Temibles Lunas!¡.
The Dark Shadow is my passion.

scapula

#2
Thanks BlackZeroX but i am not spanish it is difficult for me to decrypt you  :P

BlackZeroX

It is recommended to use the lines as well ... you should check the returns and other little things ... TerminateProcess such as whether the term is not implemented or wrongly the APP then do a CloseHandle ...

power by:  Google Translate

Dulces Lunas!¡.
The Dark Shadow is my passion.

Elemental Code

Cita de: BlackZeroX (Astaroth) en  6 Noviembre 2011, 08:36 AM
It is recommended to use the lines as well

Cita de: BlackZeroX (Astaroth) en  6 Noviembre 2011, 08:36 AM
No es recomendable usar las lineas asi...

Google translate fails a lot :S

The spanish line said:

Its NOT recommended to use the lines like that.

Powered by: 8 fucking years studying inglish :(


I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas

ssccaann43 ©

Cita de: Elemental Code en  6 Noviembre 2011, 20:21 PM
Powered by: 8 fucking years studying inglish :(

Jajajajajaja... 8 Años? y escribes INGLISH
- Miguel Núñez
Todos tenemos derechos a ser estupidos, pero algunos abusan de ese privilegio...
"I like ^TiFa^"

Elemental Code


I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas

scapula


BlackZeroX

#8
vb6 genera ejecutables para 32 bits... puede que esto sea lo que interfiere en todo esto... igual no te recomiendo que ejecutes nada de vb6 en una arquitectura de 64bits.

Dulces Lunas!¡.
The Dark Shadow is my passion.

scapula

#9
ok i have test on Win 7 32 and 64 bit with notepad and not work