In my program, I would like to have a list with all the open programs/windows on my pc. How do I do that???
Also, how can u close running programs or windows using the list that has all the window names.
Printable View
In my program, I would like to have a list with all the open programs/windows on my pc. How do I do that???
Also, how can u close running programs or windows using the list that has all the window names.
If you actually use the search feature of this page you'll find your answers quicker than just sitting there waiting for someone to do your homework .
*Throws the Dog a Bone* :(
http://forums.vb-world.net/showthrea...threadid=30190
[]P
Code:'Put this in a module, getwindows will return with an array of handles
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private handles&(), counter&
Private Function EnmWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sCaption As String * 255
ReDim Preserve handles(counter)
handles(counter) = hwnd
counter = counter + 1
EnumWindowsProc = hwnd
End Function
Public Function GetWindows()
ReDim handles(0)
counter = 0
Call EnumWindows(AddressOf EnmWinProc, 0&)
GetWindows = handles
End Function
'Put this on the form
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
'And hows you use them:
For Each n In GetWindows
'To add it to a list
List1.AddItem n
'To close them:
PostMessage n, WM_CLOSE, 0, 0
PostMessage n, WM_DESTROY, 0, 0
Next n