I'm trying to make a simple shutdown program, but it takes my slow computer to shutdown 5-10 big programs, so to save time I want the program to shutdown all open windows for me. I'v got a code to close the window, but how would I get a list of open windows and maybe put them in an array.

Shutdown code:

In module
VB Code:
  1. Option Explicit
  2.  
  3. Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  4.  
  5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  6.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  7. Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
  8.         (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
  9. Private Declare Function EnumWindows Lib "user32.dll" _
  10.         (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  11.  
  12. 'close apps
  13. Private Const WM_CLOSE = &H10
  14. Private Const WM_QUIT = &H12
  15. Private Target As String
  16.  
  17. ' Check a returned task to see if we should kill it.
  18. Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
  19. Dim buf As String * 256
  20. Dim title As String
  21. Dim length As Long
  22.  
  23.     ' Get the window's title.
  24.     length = GetWindowText(app_hWnd, buf, Len(buf))
  25.     title = Left$(buf, length)
  26.  
  27.     ' See if this is the target window.
  28.     If InStr(title, Target) <> 0 Then
  29.         ' Kill the window.
  30.         SendMessage app_hWnd, WM_CLOSE, 0, 0
  31.     End If
  32.  
  33.     ' Continue searching.
  34.     EnumCallback = 1
  35. End Function
  36. ' Ask Windows for the list of tasks.
  37. Public Sub TerminateTask(app_name As String)
  38.     Target = app_name
  39.     EnumWindows AddressOf EnumCallback, 0
  40. End Sub

Close code
VB Code:
  1. TerminateTask "Microsoft Visual Basic"

Any help appreciated!