1) I want to Close all mozilla firefox windows running , for that to happen as i know there is two ways
a) to use link label
b) findwindow

Link Label finds the mozilla browser but with the found browser i can get the url of the browser but i cannot get the title so i will not be able to get the hwnd value using findwindow function
because findwindow function needs title of the page not the url .

If i try using just findwindow i can just find window which matches the exact page title like ,"Mozilla Firefox Start Page - Mozilla Firefox"
but the problem is for each page the title of the page changes so i can never get the hwnd value .

So Please suggest me some method to find hwnd value of mozilla browser
or way to find hwnd value of mozilla application

TOTALLY WHAT I WANT IS TO JUST CLOSE ALL MOZILLA FIREFOX BROWSERS.

Recommended Answers

All 5 Replies

Check process id of all mozilla.exe running and kill them.

I was thinking along these lines. Play around a bit. Got it from another site. It worked fine in my testing. -

Public Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 'OR
Public Declare Function TerminateThread Lib "kernel32" Alias "TerminateThread" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long 'OR
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

'Use the following followed by Mozilla.exe as in brackets above

WM_CLOSE

I hope this helps...

coollife, I have actually find something much better. I have tested this and it works fine. -

'In a module add the following ---
Public 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 * 260 
End Type 
'------------------------------------------------------- 
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, _
ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long 

Public Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long 

Public Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long 

Public Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" Alias "CreateToolhelp32Snapshot" ( _
ByVal lFlags As Long, lProcessID As Long) As Long 

Public Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, _
ByVal uExitCode As Long) As Long 

Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long

'Then the following ---->
Public Sub KillProcess(NameProcess As String) 
Const PROCESS_ALL_ACCESS = &H1F0FFF 
Const TH32CS_SNAPPROCESS As Long = 2& 
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 
Dim WinDirEnv As String 
        
       If NameProcess <> "" Then 
          AppCount = 0 

          uProcess.dwSize = Len(uProcess) 
          hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&) 
          RProcessFound = ProcessFirst(hSnapshot, uProcess) 
  
          Do 
            i = InStr(1, uProcess.szexeFile, Chr(0)) 
            SzExename = LCase$(Left$(uProcess.szexeFile, i - 1)) 
            WinDirEnv = Environ("Windir") + "\" 
            WinDirEnv = LCase$(WinDirEnv) 
        
            If Right$(SzExename, Len(NameProcess)) = LCase$(NameProcess) Then 
               AppCount = AppCount + 1 
               MyProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID) 
               AppKill = TerminateProcess(MyProcess, ExitCode) 
               Call CloseHandle(MyProcess) 
            End If 
            RProcessFound = ProcessNext(hSnapshot, uProcess) 
          Loop While RProcessFound 
          Call CloseHandle(hSnapshot) 
       End If 

End Sub 

'In your form by u ing a command button etc, use the following --->
Call KillProcess(Mozilla.exe)
commented: great work +0

i tried your code by calling like this in form load

Call KillProcess(firefox.exe)
Call KillProcess(firefox)
Call KillProcess(Mozilla.exe)
Cal KillProcess(mozilla)

For Whatever option i try it says object required please help

AndreRet


Thanks a lot , U saved my day . Great going , Superb Dude,

Thanks
Thanks
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.