Ayuda con mataprocesos
Hola colegas.
Tengo este codigo que funciona perfectamente, me trae el nombre del ejecutable y el numero del PID para finalizar el proceso por el numero PID.
PERO MI PREGUTA ES:
COMO HAGO PARA QUE ADEMAS DE OBTENER EL NOMBRE DEL EJECUTABLE (calc.exe) ME TRAIGA LA RUTA COMPLETA (C:\windows\system32\calc.exe) ???
GRACIAS
Option Explicit
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32.dll" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32.dll" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Const TH32CS_SNAPPROCESS = &H2
Public Const MAX_PATH As Integer = 260
Public Const PROCESS_TERMINATE = &H1
Public 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 ProcessList() As String
'On Error Resume Next
Dim uProcess As PROCESSENTRY32
Dim hSnapshot As Long
Dim lRet As Long
Dim sProcess As String
Dim sPID As String
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
uProcess.dwSize = Len(uProcess)
lRet = Process32First(hSnapshot, uProcess)
Do While lRet
sProcess = Left(uProcess.szExeFile, InStr(1, uProcess.szExeFile, vbNullChar) - 1)
sPID = uProcess.th32ProcessID
lRet = Process32Next(hSnapshot, uProcess)
alert.Text1 = alert.Text1 & Chr(13) & Chr(10) & sProcess & " -- " & sPID
Loop
Call CloseHandle(hSnapshot)
ProcessList = "//" & sProcess & "//" & sProcess & sPID & "//"
End Function
Public Sub EndProcess(lPID As Long)
On Error Resume Next
Dim hProcess As Long
Dim lRet As Long
hProcess = OpenProcess(PROCESS_TERMINATE, 0&, lPID)
lRet = TerminateProcess(hProcess, 0&)
End Sub
Tengo este codigo que funciona perfectamente, me trae el nombre del ejecutable y el numero del PID para finalizar el proceso por el numero PID.
PERO MI PREGUTA ES:
COMO HAGO PARA QUE ADEMAS DE OBTENER EL NOMBRE DEL EJECUTABLE (calc.exe) ME TRAIGA LA RUTA COMPLETA (C:\windows\system32\calc.exe) ???
GRACIAS
Option Explicit
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32.dll" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32.dll" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Const TH32CS_SNAPPROCESS = &H2
Public Const MAX_PATH As Integer = 260
Public Const PROCESS_TERMINATE = &H1
Public 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 ProcessList() As String
'On Error Resume Next
Dim uProcess As PROCESSENTRY32
Dim hSnapshot As Long
Dim lRet As Long
Dim sProcess As String
Dim sPID As String
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
uProcess.dwSize = Len(uProcess)
lRet = Process32First(hSnapshot, uProcess)
Do While lRet
sProcess = Left(uProcess.szExeFile, InStr(1, uProcess.szExeFile, vbNullChar) - 1)
sPID = uProcess.th32ProcessID
lRet = Process32Next(hSnapshot, uProcess)
alert.Text1 = alert.Text1 & Chr(13) & Chr(10) & sProcess & " -- " & sPID
Loop
Call CloseHandle(hSnapshot)
ProcessList = "//" & sProcess & "//" & sProcess & sPID & "//"
End Function
Public Sub EndProcess(lPID As Long)
On Error Resume Next
Dim hProcess As Long
Dim lRet As Long
hProcess = OpenProcess(PROCESS_TERMINATE, 0&, lPID)
lRet = TerminateProcess(hProcess, 0&)
End Sub
Respuesta de caerices
-1
2 respuestas más de otros expertos
Respuesta de Roberto Alvarado
1
Respuesta de denciso
-1