|
|
|
Click here to copy the following block | Const MAX_PATH As Long = 260
Private 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
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As _ Long, lpdwProcessId As Long) As Long Private Declare Function CreateToolhelpSnapshot Lib "Kernel32" Alias _ "CreateToolhelp32Snapshot" (ByVal lFlgas As Long, ByVal lProcessID As Long) _ As Long Private Declare Function ProcessFirst Lib "Kernel32" Alias "Process32First" _ (ByVal hSnapshot As Long, procEntry As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "Kernel32" Alias "Process32Next" _ (ByVal hSnapshot As Long, procEntry As PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
Function ExeNameFromWindow(ByVal hWnd As Long) As String Dim threadID As Long Dim processID As Long Dim hSnapshot As Long Dim procEntry As PROCESSENTRY32 Dim success As Long Dim i As Integer Const TH32CS_SNAPPROCESS As Long = 2& hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) If hSnapshot = -1 Then Exit Function threadID = GetWindowThreadProcessId(hWnd, processID) If threadID = 0 Or processID = 0 Then Exit Function
procEntry.dwSize = Len(procEntry) success = ProcessFirst(hSnapshot, procEntry) Do While success If procEntry.th32ProcessID = processID Then ExeNameFromWindow = Left$(procEntry.szexeFile, _ InStr(procEntry.szexeFile & vbNullChar, vbNullChar) - 1) Exit Do End If success = ProcessNext(hSnapshot, procEntry) Loop CloseHandle hSnapshot End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|