Connaitre le nom d'executable d'une application qui tourne

Résolu
l0st3d Messages postés 205 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 13 novembre 2009 - 20 mai 2004 à 00:56
l0st3d Messages postés 205 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 13 novembre 2009 - 6 févr. 2005 à 07:50
Salut
je vais etre clair dans ma question

j'utilise la commande qui suit pour listé les programmes actif sous winows

Public Sub ProcessList()

Dim hwnd As Long
Dim TitreFenetre As String * 255
Dim Titre As String
Dim papa
hwnd = NextWindow(RecupHandleBureau(), 5)
Do While hwnd <> 0
TitreFenetre = String(255, 0)
R = TxtWindow(hwnd, TitreFenetre, 255)
papa = idPapa(hwnd)
If TitreFenetre <> String(255, 0) Then
Titre = TitreFenetre
Titre = Left(Titre, R)
'Set lst = frmPrinc.List.ListItems.Add(, , Titre)
Term.AddText " " & hwnd & " : " & Titre & vbCrLf, ColorTheme.wxbPLUGINOutput
' lst.SubItems(1) = hWnd
' lst.SubItems(2) = papa
End If
hwnd = NextWindow(hwnd, 2)
LoopColorTheme.wxbPLUGINOutput
End Sub

Ma question est la suivante, je voudrai savoir si je peut récupéré le nom de programme d'un handle (son nom .exe) EX: Hwnd:351 = explorer.exe

Merci d'avance 8D

2 réponses

l0st3d Messages postés 205 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 13 novembre 2009
6 févr. 2005 à 07:50
Jai trouver mon bonheur sur http://www.vbfrance.com/code.aspx?ID=7069

seulement en ajoutant l'API GetWindowThreadProcessId pour soutirer le pid relier au handle



voici le code



Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long

Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)



Public Const MAX_PATH As Integer = 260

Public Const TH32CS_SNAPHEAPLIST = &H1

Public Const TH32CS_SNAPPROCESS = &H2

Public Const TH32CS_SNAPTHREAD = &H4

Public Const TH32CS_SNAPMODULE = &H8

Public Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)

Public Const TH32CS_INHERIT = &H80000000



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 Type aProc

aCount As Long

aProcess() As PROCESSENTRY32

End Type



Dim tmpProc As aProc



Public Function GetHandleExeName(Handle As Long) As String

Dim tProcName As String

Dim hSnapShot As Long

Dim uProcess As PROCESSENTRY32

Dim r As Long

Dim tPID As Long, temp As Long



temp = GetWindowThreadProcessId(Handle, tPID)

'Debug.Print tPID & ":" & temp

' MsgBox temp

'Takes a snapshot of the processes

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)

'set the length of our ProcessEntry-type

uProcess.dwSize = Len(uProcess)



'Retrieve information about the first process encountered in our system snapshot

uProcess.szExeFile = vbNullString

r = Process32First(hSnapShot, uProcess)

Do While r

If tPID = uProcess.th32ProcessID Then

'Debug.Print uProcess.szExeFile


GetHandleExeName = Trim(Replace(uProcess.szExeFile, Chr(0), ""))

Exit Function

End If

'Retrieve information about the next process recorded in our system snapshot

uProcess.szExeFile = vbNullString

r = Process32Next(hSnapShot, uProcess)

Loop

'close our snapshot handle

GetHandleExeName = "[Pas d'exécutable trouvé]"



CloseHandle hSnapShot

End Function
3
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
26 juin 2004 à 10:08
salut

utilise l'api GetProcessImageFileName qui renvoie le nom du process à partir de son handle

voilà

ShareVB
0
Rejoignez-nous