2
« en: Viernes 23 de Abril de 2004, 16:35 »
Buenas
Mi pregunta es ¿se puede eliminar un proceso de memoria sin tener que correr antes esa aplicacion para poder eliminarla?
De antemano gracias.
Este es el codigo: (un formulario, tres botones, una caja de texto y un modulo)
Option Explicit
Private Sub cmdStart_Click()
Dim sTemp As String
sTemp = Trim$(txtProcess)
If sTemp = "" Then Exit Sub
glPid = Shell(sTemp, vbNormalFocus)
If glPid = 0 Then
MsgBox "Could not start process", vbExclamation, "Error"
End If
End Sub
Private Sub cmdKill_Click()
Dim i As Long
Call fEnumWindows
For i = 1 To colHandle.Count
glHandle = colHandle.Item(i)
Call SendMessage(glHandle, WM_CLOSE, 0&, 0&)
Next
End Sub
Private Sub cmdQuit_Click()
Unload Me
End Sub
y el modulo
Option Explicit
Public glPid As Long
Public glHandle As Long
Public colHandle As New Collection
Public Const WM_CLOSE = &H10
Public Const WM_DESTROY = &H2
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As Long
Dim lParent As Long
Dim lThreadId As Long
Dim lProcessId As Long
fEnumWindowsCallBack = 1
lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)
If glPid = lProcessId Then
lParent = GetParent(hwnd)
If lParent = 0 Then
colHandle.Add hwnd
End If
End If
End Function
Public Function fEnumWindows() As Boolean
Dim hwnd As Long
Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)
End Function