Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 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_QUIT = &H12
Private Sub Form_Load() Dim hwndShell As Long, i As Long hwndShell = FindWindow("Progman", vbNullString) i = PostMessage(hwndShell, WM_QUIT, 0, 0) If i = 0 Then Exit Sub Do While True '等待原先的Shell结束 hwndShell = FindWindow("Progman", vbNullString) If hwndShell = 0 Then Exit Do End If Loop Shell "Explorer.exe", vbNormalFocus '执行新的Shell End Sub