1.如果是结束程序,直接写 End2.如果遍历遍历本程序打开的窗口,可以在打开时记录每个窗口的句柄,在关闭时用 sendmessage 向其发送 WM_CLOSE 消息来关闭3.如果是遍历系统中有形状的窗口,用以下函数:(很早以前写的)
Public Sub CloseAllApps()
        Dim hwCurr As Long, hwCur As Long
        Dim intLen As Long
        Dim strTitle As String
        Dim strT As Long
        Dim msgback As Long
        Dim flag As Boolean
        
              
         hwCurr = GetWindow(frmSysLoading.hwnd, GW_HWNDFIRST)
        
        
        Do While hwCurr
           If hwCurr <> frmSysLoading.hwnd And TaskWindow(hwCurr) Then
              
            intLen = GetWindowTextLength(hwCurr) + 1
              strTitle = Space$(intLen)
              intLen = GetWindowText(hwCurr, strTitle, intLen)
            
              If intLen > 0 Then
                 
                 hwCur = hwCurr
                 
                 hwCurr = GetWindow(hwCurr, GW_HANDNEXT)
                 
                 
                 strT = InStr(strTitle, "Internet Explorer")
                 
                 If strT > 0 Then
                   SendMessage hwCur, WM_SYSCOMMAND, SC_CLOSE, 0
                 Else
                   SendMessage hwCur, WM_CLOSE, 0, 0
                   flag = False
                   
                   Do While flag = False
                           
                            intLen = GetWindowTextLength(hwCur) + 1
                            strTitle = Space$(intLen)
                            intLen = GetWindowText(hwCur, strTitle, intLen)
                            If intLen > 0 Then
                               SendMessage hwCur, WM_CLOSE, 0, 0
                               flag = False
                            Else
                               flag = True
                            End If
                    Loop
                  End If
              Else
                hwCurr = GetWindow(hwCurr, GW_HANDNEXT)
              End If
           Else
              hwCurr = GetWindow(hwCurr, GW_HANDNEXT)
           End If
        Loop
End SubFunction TaskWindow(hwCurr As Long) As Long
     Dim lngStyle As Long
     Dim IsTask As Long
     
     IsTask = WS_VISIBLE Or WS_BORDER
     
     lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
     If (lngStyle And IsTask) = IsTask Then
         TaskWindow = True
     End If
     
End Function4.如果是遍历没有形状的,即没有窗体的进程,用函数 EnumWindows 
 以下是实例代码,没有加关闭,结合上面3的方法自己试试写关闭'Add this code to a form
Private Sub Form_Load()
    'Set the form's graphics mode to persistent
    Me.AutoRedraw = True
    'call the Enumwindows-function
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
'Add this code to a module
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    Dim sSave As String, Ret As Long
    Ret = GetWindowTextLength(hwnd)
    sSave = Space(Ret)
    GetWindowText hwnd, sSave, Ret + 1
    Form1.Print Str$(hwnd) + " " + sSave
    'continue enumeration
    EnumWindowsProc = True
End Function