Old 13th April 2011, 21:05   #1
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
How to close firefox in nsis?

Here is what I did to close firefox,

FindWindow $0 'MozillaWindowClass' ''

${If} $0 <> 0
SendMessage $0 ${WM_CLOSE} 0 0
${EndIf}

But it doesn't work. How can I achieve that? Thanks.
JohnChen is offline   Reply With Quote
Old 13th April 2011, 22:12   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,184
PHP Code:
!include LogicLib.nsh
loop
:
FindWindow $"MozillaUIWindowClass"
${If} $<> 0
    SendMessage 
$0 0x0112 0xF060 0    
    Sleep 250
    
goto loop
${EndIf} 
If firefox has "confirm close with multiple tabs open", who knows what will happen, you might want to limit the loop to 50 retries or so...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th April 2011, 23:07   #3
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Anders View Post
PHP Code:
!include LogicLib.nsh
loop
:
FindWindow $"MozillaUIWindowClass"
${If} $<> 0
    SendMessage 
$0 0x0112 0xF060 0    
    Sleep 250
    
goto loop
${EndIf} 
If firefox has "confirm close with multiple tabs open", who knows what will happen, you might want to limit the loop to 50 retries or so...
Thanks for your reply. It doesn't work. FindWindow $0 "MozillaUIWindowClass" always set $0 to zero. Any further ideas? Thank you very much!
JohnChen is offline   Reply With Quote
Old 14th April 2011, 00:46   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,184
It worked when I tested it (Firefox 3.6) The class name is a internal thing and could change between releases. Use http://catch22.net/software/winspy to find the class name

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th April 2011, 11:28   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Firefox 4 is just called MozillaWindowClass.

Stu
Afrow UK is offline   Reply With Quote
Old 14th April 2011, 15:35   #6
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Anders View Post
It worked when I tested it (Firefox 3.6) The class name is a internal thing and could change between releases. Use http://catch22.net/software/winspy to find the class name
It works in firefox 3.6 but it doesn't work in firefox 4 even though I use class name "MozillaWindowClas" for firefox 4(I find out this name by using Spy++). Any idea why it doesn't work in firefox 4?
JohnChen is offline   Reply With Quote
Old 14th April 2011, 15:37   #7
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Afrow UK View Post
Firefox 4 is just called MozillaWindowClass.

Stu
Yes, you are right.
JohnChen is offline   Reply With Quote
Old 14th April 2011, 16:36   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,184
well, the message is WM_SYSCOMMAND + SC_CLOSE so it should work, but you could try WM_CLOSE as well, and if both fail, bring out the big hammer and call DestroyWindow with the system plugin...

(But why not just ask the user to close firefox? They might want to save bookmarks etc)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th April 2011, 17:34   #9
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Anders View Post
well, the message is WM_SYSCOMMAND + SC_CLOSE so it should work, but you could try WM_CLOSE as well, and if both fail, bring out the big hammer and call DestroyWindow with the system plugin...

(But why not just ask the user to close firefox? They might want to save bookmarks etc)
I tried both WM_SYSCOMMAND + SC_CLOSE and WM_CLOSE in Firefox 4. They don't work. If you like, you can try them in Firefox 4 too. It won't take much time if you already tried it in Firefox 3.6. They just simply don't work.
Could you give me an example how to use DestroyWindow with the system plugin? Thanks a lot.
JohnChen is offline   Reply With Quote
Old 14th April 2011, 18:08   #10
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,184
PHP Code:
!include LogicLib.nsh
StrCpy 
$1 0
loop
:
FindWindow $"MozillaUIWindowClass"
${IfThen} $${|} FindWindow $"MozillaWindowClass" ${|}
${If} $
<> 0
    SendMessage 
$0 0x0112 0xF060 0
    
    Sleep 500
    IntOp 
$$1
    IntCmp 
$1 25 "" loop
${EndIf} 
This works in both 3.6 and 4 on XP (In my non standard FF configuration), but like I said, you should ask the user, not close the windows on your own.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th April 2011, 18:56   #11
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Anders View Post
PHP Code:
!include LogicLib.nsh
StrCpy 
$1 0
loop
:
FindWindow $"MozillaUIWindowClass"
${IfThen} $${|} FindWindow $"MozillaWindowClass" ${|}
${If} $
<> 0
    SendMessage 
$0 0x0112 0xF060 0
    
    Sleep 500
    IntOp 
$$1
    IntCmp 
$1 25 "" loop
${EndIf} 
This works in both 3.6 and 4 on XP (In my non standard FF configuration), but like I said, you should ask the user, not close the windows on your own.
I know there is "confirm close" dialog in firefox when the user closes firefox. Right now, I just could not trigger this dialog no matter what I do. Do you have any idea how to achieve that? Thanks a lot.
JohnChen is offline   Reply With Quote
Old 14th April 2011, 20:30   #12
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
I think you should change your strategy. Ask the user to close Firefox themselves. You can either do this with your own code (similar to what we use in this topic) or use a plug-in such as LockedList.

Stu
Afrow UK is offline   Reply With Quote
Old 14th April 2011, 22:16   #13
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Afrow UK View Post
I think you should change your strategy. Ask the user to close Firefox themselves. You can either do this with your own code (similar to what we use in this topic) or use a plug-in such as LockedList.

Stu
So should I just call MessageBox MB_OK "Please Close Firefox" in the script? Thanks.
JohnChen is offline   Reply With Quote
Old 14th April 2011, 22:46   #14
Smurge
Junior Member
 
Join Date: Apr 2008
Posts: 21
i think yes!

i would never install a program that will automatically taskkill my firefox.exe!

Take a look at that LockedList plugin as Afrow UK suggested.
What you have to use depends on your purpose/program. but never kill a task on the user system unasked !!!

bye
Smurge is offline   Reply With Quote
Old 15th April 2011, 00:31   #15
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You don't just have to have a message box. Using FindWindow you can detect whether Firefox has been closed or not and keep asking them to close Firefox until FindWindow returns 0. Using LockedList has more features of course.

Stu
Afrow UK is offline   Reply With Quote
Old 15th April 2011, 19:35   #16
JohnChen
Member
 
Join Date: Mar 2011
Posts: 80
Quote:
Originally Posted by Afrow UK View Post
You don't just have to have a message box. Using FindWindow you can detect whether Firefox has been closed or not and keep asking them to close Firefox until FindWindow returns 0. Using LockedList has more features of course.

Stu
I don't quite get what you meant. Without using message box, how can I "keep asking them to close Firefox"? I should have some way to inform the users of closing the firefox, right? Thanks.
JohnChen is offline   Reply With Quote
Old 15th April 2011, 21:12   #17
Highcoder
Member
 
Join Date: Jan 2011
Posts: 69
...

He means that you have not to show this messegebox always. You can use the "find firefox window" checkup to show the messagebox only if firefox is open.

PHP Code:
!include LogicLib.nsh 
StrCpy 
$1 0 
loop

FindWindow $"MozillaUIWindowClass" 
${IfThen} $${|} FindWindow $"MozillaWindowClass" ${|} 
${If} $
<> 
MessageBox MB_OK
|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND "Close Firefox now and press ok to continue."  
goto loop 
${EndIf} 
cheers
Highcoder is offline   Reply With Quote
Old 20th April 2011, 09:40   #18
zenpoy
Junior Member
 
Join Date: Feb 2011
Posts: 38
Quote:
Originally Posted by JohnChen View Post
I know there is "confirm close" dialog in firefox when the user closes firefox. Right now, I just could not trigger this dialog no matter what I do. Do you have any idea how to achieve that? Thanks a lot.
You should create a new profile: firefox.exe -P
and create a new profile for testing.
zenpoy is offline   Reply With Quote
Old 20th April 2011, 17:22   #19
Squirre1
Member
 
Join Date: Aug 2001
Posts: 55
Send a message via ICQ to Squirre1
Would it not achieve the same affect to do the following...
PHP Code:
    !insertmacro logme ${INSTLOG"Locating and terminating running firefox.exe processes" b
    
${nsProcess::FindProcess"firefox.exe" $0
    
${If} $== '0'
      
!insertmacro logme ${INSTLOG"- Running Process Found: firefox.exe" l
      
!insertmacro logme ${INSTLOG"- Terminating Process: firefox.exe" l
      
${nsProcess::KillProcess"firefox.exe" $0
      
!insertmacro logme ${INSTLOG"- Terminate Process Returned Code: $0" l
    
${Else}
      !
insertmacro logme ${INSTLOG"- Running Process Not Found: firefox.exe" l
    
${EndIf} 
Disregard the logme macros, that is a making of my own... Depends on what you are trying to accomplish though, but this is what I use.

http://nsis.sourceforge.net/NsProcess_plugin

Squirre1
Squirre1 is offline   Reply With Quote
Old 20th April 2011, 22:57   #20
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
That will not work if and when they make an official 64-bit build of Firefox. FindWindow is safer (when you have a class name).

Stu
Afrow UK is offline   Reply With Quote
Old 22nd April 2011, 03:05   #21
mrphantuan
Banned
 
Join Date: Nov 2010
Posts: 7
Firefox 4 is just called MozillaWindowClass.






_________________
noi that fami,noi that 190|
mrphantuan is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump