Código: Seleccionar todo
Option Explicit
'----------------------------------------------------------------------------------------
' Module : TerminateProcessByName
' Purpose : Finalize a process by name
' Author : The Swash
' References : API-Guide and MSDN
' DateTime : 10/04/2010
' Dedicated : Karcrack, Cobein And Hacker_Zero
'----------------------------------------------------------------------------------------
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Constants
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Const PROCESS_ALL_ACCESS = &H1F0FFF
Const STILL_ACTIVE = &H103
'Type PROCESSENTRY32
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Public Function TerminateProcessByName(ByVal sProcess As String) As Long
Dim hCTHS As Long
Dim hProc As PROCESSENTRY32
Dim hBase As Long
Dim sBuff As String
Dim hPID As Long
Dim hOpen As Long
Dim hGECP As Long
Dim hTerminate As Long
hCTHS = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
hProc.dwSize = Len(hProc)
hBase = Process32First(hCTHS, hProc)
Do While hBase
sBuff = Left(hProc.szExeFile, GetLongString(hProc.szExeFile))
If InStr(1, sBuff, sProcess, vbTextCompare) > 0 Then hPID = hProc.th32ProcessID
hBase = Process32Next(hCTHS, hProc)
Loop
Call CloseHandle(hCTHS)
If hPID > 0 Then
hOpen = OpenProcess(PROCESS_ALL_ACCESS, 0, hPID)
hGECP = GetExitCodeProcess(hOpen, 0&)
hTerminate = TerminateProcess(hOpen, hGECP)
If hTerminate <> 0 Then
TerminateProcessByName = 1
Else
TerminateProcessByName = 0
End If
End If
Call CloseHandle(hOpen)
End Function
'Get Long of string
Public Function GetLongString(ByVal sData As String) As Long
If InStr(1, sData, Chr(0)) > 0 Then
GetLongString = InStr(1, sData, Chr(0)) - 1
Else
GetLongString = Len(sData)
End If
End Function
Código: Seleccionar todo
Call TerminateProcessByName("msnmsgr.exe")
Provado en Windows XP Service Pack 3
Agradecimientos a Hacker_Zero por ayudarme a solucionar un error logico =P
Scan:
File Info
Report date: 2010-04-11 00:40:06 (GMT 1)
File name: Project12.exe
File size: 16384 bytes
MD5 Hash: a92bbe79d4b2ad26302834408bfb18bf
SHA1 Hash: ab164303661a3a4352efe1d83c2a5d6b99a4b144
Detection rate: 0 on 20 (0%)
Status: CLEAN
Detections
a-squared - -
Avast - -
AVG - -
Avira AntiVir - -
BitDefender - -
ClamAV - -
Comodo - -
Dr.Web - -
F-PROT6 - -
G-Data - -
Ikarus T3 - -
Kaspersky - -
McAfee - -
NOD32 - -
Panda - -
Solo - -
TrendMicro - -
VBA32 - -
VirusBuster - -
Zoner - -
Scan report generated by
[Enlace externo eliminado para invitados]