El problema es que en todas las ramas del treeview me pone la misma ruta en ves de poner la ruta de cada proceso.
Le e dado muchas vueltas, aver si alguien de ustedes tiene la cabeza despejada y da con la solucion. Os lo agradeceria la verdad.
Public Function listar_procc()
Dim Buffer As String
Dim handle As Long
Dim ret As Long
Dim Ruta As String
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
R = Process32First(hSnapShot, uProcess)
'Recorre los procesos y agrega la información al ListView
Do While R
R = Process32Next(hSnapShot, uProcess)
'recupera el handle, creo que aki esta el problema
handle = CreateToolhelp32Snapshot(TH32CS_SNAPALL, uProcess.th32ProcessID)
Buffer = Space(255)
ret = GetModuleFileNameExA(handle, 0, Buffer, 255)
'Le elimina los espacios nulos a la cadena devuelta
Ruta = Left(Buffer, ret)
Set nodos(1) = Form1.TreeView1.Nodes.Add(nodos(0), tvwChild, , uProcess.szExeFile)
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Nombre de ventana: " & Get_Caption_Ventana(handle)
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Ruta del archivo: " & Ruta
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Pid: " & uProcess.th32ProcessID
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Handle : " & handle
Loop
Call CloseHandle(hSnapShot)
End Function
Hola, fijate si esto te ayuda, agrega un timer y compilado,
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwprocessid As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI: x As Long: y As Long: End Type
Private Sub Form_Load()
Me.BackColor = vbBlack: Me.ForeColor = vbWhite: Me.FontBold = True
Me.Top = 0: Me.Left = 0: Me.Width = 6450: Me.Height = 1000
Me.BorderStyle = 5: Timer1.Interval = 100
End Sub
'Private Sub Form_Load(): Timer1.Interval = 100: End Sub
Private Sub Timer1_Timer()
Call SetWindowPos(Me.Hwnd, -1, 0, 0, 0, 0, &H2 Or &H1)
Dim Cor As POINTAPI: Dim retorno As Long: retorno = GetCursorPos(Cor)
Dim Handle As Long: Handle = WindowFromPoint(Cor.x, Cor.y)
Dim idProc As Long: Call GetWindowThreadProcessId(Handle, idProc)
Dim Handle_Proceso As Long: Handle_Proceso = OpenProcess(&H400 + &H10, 0, idProc)
Dim Buffer As String: Buffer = Space(255)
Dim ret As Long: ret = GetModuleFileNameExA(Handle_Proceso, 0, Buffer, 255)
Dim Ruta As String: Ruta = Left(Buffer, ret): ret = CloseHandle(Handle_Proceso)
Me.Cls: Me.Print "": Me.Print Ruta: Me.Caption = "ID PROCESO = " & idProc
End Sub
Ese codigo no me sirve ya que el handle se obtiene de los punteros y\x del posicionamiento del mous. Quiero conseguir el handle con CreateToolhelp32Snapshot
Una pregunta, podes adaptar el code llegando handle por FindWindows ???
Tendria que cambiar todo el codigo, ademas de que luego tendria que buscar la forma de enumerar los procesos por las ventanas no se si me explico
Solucionado con el openprocess
Public Function listar_procc()
Dim Buffer As String
Dim handle As Long
Dim ret As Long
Dim Ruta As String
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
'Recorre los procesos y agrega la información al ListView
Do While r
r = Process32Next(hSnapShot, uProcess)
'recupera el handle
handle = OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_VM_READ, False, uProcess.th32ParentProcessID)
Buffer = Space(255)
ret = GetModuleFileNameExA(handle, 0, Buffer, 255)
'Le elimina los espacios nulos a la cadena devuelta
Ruta = Left(Buffer, ret)
Set nodos(1) = Form1.TreeView1.Nodes.Add(nodos(0), tvwChild, , uProcess.szExeFile)
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Nombre de ventana: " & Get_Caption_Ventana(handle)
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Ruta del archivo: " & Ruta
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Pid: " & uProcess.th32ProcessID
Form1.TreeView1.Nodes.Add nodos(1), tvwChild, , "Handle : " & handle
Loop
Call CloseHandle(hSnapShot)
End Function
Leete este code seguro te sirve
http://www.recursosvisualbasic.com.ar/htm/listado-api/183-listar-ruta-de-procesos-de-windows.htm