Título: Path (SRC)
Publicado por: Dessa en 24 Enero 2010, 16:34 pm
Una boludez, pero a veces puede servir, con este code se puede saber la ruta (Path) del ejetutable al que pertenece a una ventana, solo hay que pasar el puntero del mouse sobre la ventana que se quiere "investigar". 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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long 'Dessa 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()
Dim ClassName As String: ClassName = Space$(256) Dim ret As Long: ret = GetClassName(Me.hwnd, ClassName, 256) If Left$(ClassName, ret) = "ThunderFormDC" Then MsgBox "Esta aplicacion debe correr compilada", , "" End End If 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 = 16
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): Call CloseHandle(Handle_Proceso) Me.Cls: Me.Print "": Me.Print Ruta: Me.Caption = "ID PROCESO = " & idProc
End Sub
Título: Re: Path (SRC)
Publicado por: seba123neo en 24 Enero 2010, 16:41 pm
esta buena la idea ;D, lo unico que no me gusta es el tema ese de programar en una linea, la verdad casi no se puede leer el codigo.
saludos.
Título: Re: Path (SRC)
Publicado por: Dessa en 24 Enero 2010, 16:51 pm
Si, es una de mis tantas malas costumbres ;)
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 GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long 'Dessa 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
Dim CtlHandle As Long
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 = 16
End Sub
Private Sub Timer1_Timer() Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, &H2 Or &H1) Dim Cor As POINTAPI Call GetCursorPos(Cor) Dim Handle As Long Handle = WindowFromPoint(Cor.x, Cor.y) If Handle <> CtlHandle Then
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) Call CloseHandle(Handle_Proceso) Me.Cls Me.Print "" Me.Print Ruta Me.Caption = "PID = " & idProc CtlHandle = Handle
End If
End Sub
|