How can I get every app that is running like everything about it like the handel, name ect...
Printable View
How can I get every app that is running like everything about it like the handel, name ect...
Here is a program that shows you how to list all the apps running and you can also close them as well: App List and Kill
Here are two examples that you will probably find useful:
Program Closer
Terminator
Use the EnumWindows function. Next example will retrieve the Name, Class and hWnd of all the running windows.
Code for a Module
Code for a Form with a CommandButtonCode:Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim Length As Long
Dim Buffer As String
Dim Temp As String
Dim sClass As String
Dim icLength As Integer
Static iCount As Integer
iCount = iCount + 1
Length = GetWindowTextLength(hwnd) + 1
sClass = Space(255)
If Length > 1 Then
Buffer = Space(Length)
'Get the name
GetWindowText hwnd, Buffer, Length
'Get the Class
icLength = GetClassName(hwnd, sClass, 255)
'Display the Name, Class and hWnd
sClass = Left(sClass, icLength)
Debug.Print Left(Buffer, Length - 1) & " - " & sClass & " - " & hwnd
End If
EnumWindowsProc = 1
End Function
Code:Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
Code:'open a std project
'this project uses a list box (List1)
'list all running task in list1 with there hwnd
'add a bas module and put this code in it
'
Option Explicit
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" _
(ByVal hwnd As Long) As Long
'
Private Declare Function GetWindowTextLength Lib _
"user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
lpString As String, ByVal cch As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Public Sub LoadTaskList()
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Form1.List1.Clear
CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
While CurrWnd <> 0
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
If TaskName <> Form1.Caption Then
Form1.List1.AddItem TaskName & " " & CurrWnd
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
End Sub
' put this in the form load event of your form
Call LoadTaskList