|
321
|
Programación / Programación Visual Basic / Re: listar nombre de ventana de los procesos. No lo consigo.
|
en: 10 Marzo 2009, 17:36 pm
|
Pero parece que no encuentra el handle. Alguien me puede explicar el motivo?
A ˇˇ, En el proceso vb leido con openprocess me da un handle pero en otro programa me sale otro handle en el mismo proceso.
El handle que usas para abrir un proceso (openprocess) es el PID o ID del proceso. Este Handle_Proceso no es mismo handle de las ventanas (aplicaciones) que se enumeran con EnumWindows
|
|
|
324
|
Programación / Programación Visual Basic / Re: Ayuda con este codigo. Detectar ruta a partir del handle.
|
en: 6 Marzo 2009, 20:26 pm
|
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
|
|
|
326
|
Programación / Programación Visual Basic / Re: [Duda] detectar proceso activo
|
en: 4 Marzo 2009, 16:38 pm
|
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function EnumProcesses Lib "PSAPI.DLL" (lpidProcess As Long, ByVal cb As Long, cbNeeded As Long) As Long Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, lphModule As Long, ByVal cb As Long, lpcbNeeded As Long) As Long Private Declare Function GetModuleBaseName Lib "PSAPI.DLL" Alias "GetModuleBaseNameA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long Private Const PROCESS_VM_READ = &H10 Private Const PROCESS_QUERY_INFORMATION = &H400
Private Function EstaCorriendo(ByVal NombreDelProceso As String) As Boolean Const MAX_PATH As Long = 260 Dim lProcesses() As Long, lModules() As Long, N As Long, lRet As Long, hProcess As Long Dim sName As String NombreDelProceso = UCase$(NombreDelProceso) ReDim lProcesses(1023) As Long
If EnumProcesses(lProcesses(0), 1024 * 4, lRet) Then For N = 0 To (lRet \ 4) - 1 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, lProcesses(N)) If hProcess Then ReDim lModules(1023) If EnumProcessModules(hProcess, lModules(0), 1024 * 4, lRet) Then sName = String$(MAX_PATH, vbNullChar) GetModuleBaseName hProcess, lModules(0), sName, MAX_PATH sName = Left$(sName, InStr(sName, vbNullChar) - 1) If Len(sName) = Len(NombreDelProceso) Then If NombreDelProceso = UCase$(sName) Then EstaCorriendo = True: Exit Function End If End If End If CloseHandle hProcess Next N End If End Function
Private Sub Form_Load() Timer1.Interval = 300 Label1 = "" End Sub
Private Sub Timer1_Timer() If EstaCorriendo("calc.exe") = True Then Label1 = "ACTIVO" Else Label1 = "INACTIVO" End If End Sub
|
|
|
|
|
|
|