Ну например, отлавливай таймером окно с заголовком "internet explorer" и закрывай его. Найти окно тебе поможет FindWindow,а закрыть окно - SendMessage.
Прошлый раз я немного не так посоветовал... Когда ты FindWindow_ом будешь искать окно Explorera, окно его будет обзываться "Васи Пупкина страничка - Microsoft Internet Explorer" Соответственно нужна функция находящая манипулятор окна по ЧАСТИ заголовка. Короче на тебе код. На форму 1 буттон (Command1) и весь код в форму. Нажмёшь на буттон, в инпут-боксе напишешь ЧАСТЬ заголовка нужного окна (напр: Internet Explorer или Explorer) и будет тебе великое сччастье...
Option Explicit Private Const WM_CLOSE = &H10 Private Const GW_HWNDFIRST = 0 Private Const GW_HWNDNEXT = 2 Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long 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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Function MyFindWindow(hWnd As Long, strCaption As String) As Long Dim CurrWnd As Long, Length As Long, TaskName As String, parent As Long CurrWnd = GetWindow(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 TaskName = LCase(TaskName) strCaption = LCase(strCaption) If InStr(1, TaskName, strCaption) > 0 Then MyFindWindow = CurrWnd End If CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT) DoEvents Wend End Function
Private Sub Command1_Click() Dim sTmp As String, hW As Long, res As Long sTmp = InputBox("строка присутствующая в заголовке") If Len(sTmp) <= 0 Then Exit Sub ' hW = MyFindWindow(hWnd, sTmp) PostMessage hW, WM_CLOSE, 0, 0 End Sub
Justas, ты не понял. Закрывать окна я очень хорошо умею (посылаю &H10 главному окну) А мне надо сделать так, чтобы даже если окно експлорера не открыто, можно было что-нибудь сделать с файлом environ("windir") & "/Explorer.exe"
Private Const MAX_PATH = 260 Private Declare Function ProcessFirst Lib "kernel32" _ Alias "Process32First" (ByVal hSnapshot As Long, uProcess _ As PROCESSENTRY32) As Long Private Declare Function ProcessNext Lib "kernel32" _ Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As _ PROCESSENTRY32) As Long Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _ Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _ lProcessID As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject _ As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal _ dwDesiredAccess As Long, ByVal bInheritHandle As Long, _ ByVal dwProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" _ (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szexeFile As String * MAX_PATH End Type
Private Function KillApp(myName As String) As Boolean Const PROCESS_ALL_ACCESS = 0 Dim uProcess As PROCESSENTRY32 Dim rProcessFound As Long Dim hSnapshot As Long Dim szExename As String Dim exitCode As Long Dim myProcess As Long Dim AppKill As Boolean Dim appCount As Integer Dim i As Integer On Local Error GoTo Finish appCount = 0
Попробуй выгружать процесс функцией TerminateProcess.
Но есть одна трабла с 2k/XP - ты его выгружешь, а винда опять запускает. Ну а если матсдай у тебя стоит, то проблем с выгрузкой нет. Если, есть вопросы намылишь - вышлю пример.