elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 09:06  


Tema destacado: Sigue las noticias más importantes de elhacker.net en ttwitter!

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo, raul338)
| | |-+  [Sources code] Obtener Path de un programa con el handle de ventana
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Sources code] Obtener Path de un programa con el handle de ventana  (Leído 804 veces)
RHL


Desconectado Desconectado

Mensajes: 968


mental


Ver Perfil
[Sources code] Obtener Path de un programa con el handle de ventana
« en: 27 Junio 2011, 22:31 »

Hola buenas panas!  ;D
bueno aqui aportando al foro por todo lo que me han ayudado todos por mis dudas  :xD tambien quiero ayudar  :xD
este sources hecho por mi es sencillo es para obtener la ruta de un programa por medio del handle de la ventana:

es sencillo perdon por cualquier error que tenga  :P

Ejemplo de uso:

Código:
msgbox PathEXEWindow(Win) ' donde Win es el handle de la ventana

Código
Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
 
 
Private Const PROCESS_ALL_ACCESS  As Long = &H1F0FFF
Private Const MAX_PATH = 260
 
'------------------------------------------------------------------------------------------
' FUNCION: _
-------------------------------------------------------------------------------------------

 
Function PathEXEWindow(HndW As Long) As String
Dim IDp As Long, HandleProcess As Long
Dim Bufpath As String, LenBuf As Long
 
Call GetWindowThreadProcessId(HndW, IDp)
 
HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, IDp)
 
Bufpath = String$(MAX_PATH, Chr$(0))
LenBuf = MAX_PATH
 
If 0 = GetModuleFileNameExA(HandleProcess, 0, Bufpath, LenBuf) Then
   MsgBox "No se puede obtener la ruta del proceso Verifique los valores", vbCritical
   Exit Function
End If
 
PathEXEWindow = Left(Bufpath, LenBuf)
Call CloseHandle(HandleProcess)
End Function

espero que les guste y mas que les sirva  ;D


« Última modificación: 27 Junio 2011, 22:36 por Raul100 » En línea
BlackZeroX (Astaroth)
Wiki

Desconectado Desconectado

Mensajes: 2.832


I'Love...!¡.


Ver Perfil WWW
Re: [Sources code] Obtener Path de un programa con el handle de ventana
« Respuesta #1 en: 28 Junio 2011, 03:19 »

.
Solo lo ordene y le añadi una funcion...

Código
 
 
Option Explicit
 
Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
Private Const PROCESS_VM_READ           As Long = (&H10)
 
Private Const MAX_PATH                  As Long = 260
 
Enum GetFileStr
    Extensión = 1
    FileName = 2
    Ruta = 4
End Enum
 
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 Sub CloseHandle Lib "Kernel32" (ByVal hPass 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 Sub Form_Load()
   MsgBox GetPatchInfohwnd(Me.hwnd, FileName + Extensión)
   MsgBox GetPatchInfohwnd(Me.hwnd, Ruta Or Extensión)
   MsgBox GetPatchInfohwnd(Me.hwnd, Ruta Or Extensión Or FileName)
End Sub
 
' ////////////////////////////////////////////////////////////////
' // http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=17:artgetpatchinfo&catid=2:catprocmanager&Itemid=8
' ////////////////////////////////////////////////////////////////
Public Function GetPatchInfo(ByRef StrRutaFull As String, Optional ByVal Options As GetFileStr = FileName) As String
Dim lng_ptr(1)              As Long
Dim lng_aux                 As Long
    lng_aux = Len(StrRutaFull)
    lng_ptr(0) = InStrRev(StrRutaFull, "\")
    If lng_ptr(0) > 0 Then
        lng_ptr(1) = InStrRev(StrRutaFull, ".")
        If lng_ptr(1) > 0 And Not lng_ptr(0) < lng_ptr(1) Then
            lng_ptr(1) = lng_aux + 1
        End If
        If (Options And Ruta) = Ruta Then
            GetPatchInfo = Mid$(StrRutaFull, 1, lng_ptr(0)) & GetPatchInfo
        End If
        If (Options And FileName) = FileName Then
            If lng_ptr(1) = lng_aux Then
                lng_aux = lng_aux - lng_ptr(0) - 1
            Else
                lng_aux = lng_ptr(1) - lng_ptr(0) - 1
            End If
            GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(0) + 1, lng_aux)
        End If
        If (Options And Extensi&#243;n) = Extensi&#243;n Then
            GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(1), lng_ptr(1))
        End If
    End If
End Function
 
Public Function GetPatchInfohwnd(ByVal hwnd As Long, Optional GetDir As GetFileStr = Ruta) As String
Dim PID     As Long
Dim lProc   As Long
Dim sTmp    As String * MAX_PATH
 
   If Not (GetWindowThreadProcessId(hwnd, PID) = 0) Then
       lProc = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, PID)
       If Not (lProc = 0) Then
           GetPatchInfohwnd = GetPatchInfo(Mid$(sTmp, 1, GetModuleFileNameExA(lProc, 0, sTmp, MAX_PATH)), GetDir)
           CloseHandle lProc
       End If
   End If
End Function
 
 

Dulces Lunas!¡.


« Última modificación: 28 Junio 2011, 03:21 por BlackZeroX▓▓▒▒░░ » En línea

Web Principal-->[ Blog(VB6) | Host File (Public & Private) | Scan Port | (New)MyInfraPC (Descubre mi Contraseña venefi. $) ]



The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi
CAR3S?


Desconectado Desconectado

Mensajes: 331


Level xXx


Ver Perfil
Re: [Sources code] Obtener Path de un programa con el handle de ventana
« Respuesta #2 en: 28 Junio 2011, 05:08 »

buenisimo, cuando mi imaginacion se reactive, vere si lo uso :D
En línea
Hasseds

Desconectado Desconectado

Mensajes: 144



Ver Perfil
Re: [Sources code] Obtener Path de un programa con el handle de ventana
« Respuesta #3 en: 28 Junio 2011, 22:58 »

Otra opción, no será la mas profesional, pero sí otra opción  :)

Código:

Option Explicit

Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) 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 GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Function PathExeWindow(ByVal hwnd As Long, ByRef sPath As String) As Long

  Dim HProc As Long, lngPid As Long, lnglen As Long, Bfpath As String * &H104
 
  Call GetWindowThreadProcessId(hwnd, lngPid)
  HProc = OpenProcess(&H410, &H0, lngPid)
  If HProc = 0 Then Exit Function
 
  lnglen = GetModuleFileNameExA(HProc, &H0, Bfpath, &H104)
  Call CloseHandle(HProc)
  If lnglen = 0 Then Exit Function
 
  sPath = Left$(Bfpath, lnglen)
  PathExeWindow = lnglen

End Function

Private Sub Form_Load()
 
  Dim sPath As String

  If PathExeWindow(hwnd, sPath) > 0 Then
    MsgBox sPath, , "sPath"
    MsgBox Mid$(sPath, 1, InStrRev(sPath, "\")), , "sDirectorio"
    MsgBox Mid$(sPath, InStrRev(sPath, "\") + 1), , "sFile"
    MsgBox Mid$(sPath, InStrRev(sPath, ".") + 1), , "sExtencion"
  End If

End Sub

En línea

Sergio Desanti
RHL


Desconectado Desconectado

Mensajes: 968


mental


Ver Perfil
Re: [Sources code] Obtener Path de un programa con el handle de ventana
« Respuesta #4 en: 29 Junio 2011, 10:19 »

buenoo!  :D
En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Obtener handle de la ventana
Programación C/C++
XP. 1 836 Último mensaje 7 Octubre 2006, 04:54
por uniqdom
problema para encontrar el handle de una ventana
.NET
CH4ØZ 3 1,302 Último mensaje 10 Septiembre 2010, 02:08
por CH4ØZ
[Sources code] desactivando UAC
Programación Visual Basic
RHL 9 1,291 Último mensaje 8 Julio 2011, 17:28
por sabeeee
[Sources Code] GB RAT [VB][Download]
Programación Visual Basic
RHL 2 1,037 Último mensaje 19 Octubre 2011, 19:50
por TGa.
[Sources Code] Virus Stuxnet
Análisis y Diseño de Malware
RHL 9 1,417 Último mensaje 19 Octubre 2011, 13:18
por Karcrack
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines