Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   How to close firefox in nsis? (http://forums.winamp.com/showthread.php?t=329630)

JohnChen 13th April 2011 20:05

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.

Anders 13th April 2011 21:12

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...

JohnChen 13th April 2011 22:07

Quote:

Originally Posted by Anders (Post 2763250)
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!

Anders 13th April 2011 23:46

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

Afrow UK 14th April 2011 10:28

Firefox 4 is just called MozillaWindowClass.

Stu

JohnChen 14th April 2011 14:35

Quote:

Originally Posted by Anders (Post 2763268)
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 14th April 2011 14:37

Quote:

Originally Posted by Afrow UK (Post 2763339)
Firefox 4 is just called MozillaWindowClass.

Stu

Yes, you are right.

Anders 14th April 2011 15:36

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)

JohnChen 14th April 2011 16:34

Quote:

Originally Posted by Anders (Post 2763440)
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.

Anders 14th April 2011 17:08

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.

JohnChen 14th April 2011 17:56

Quote:

Originally Posted by Anders (Post 2763463)
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.

Afrow UK 14th April 2011 19:30

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

JohnChen 14th April 2011 21:16

Quote:

Originally Posted by Afrow UK (Post 2763496)
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.

Smurge 14th April 2011 21:46

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

Afrow UK 14th April 2011 23:31

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

JohnChen 15th April 2011 18:35

Quote:

Originally Posted by Afrow UK (Post 2763520)
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.

Highcoder 15th April 2011 20:12

...
 
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

zenpoy 20th April 2011 08:40

Quote:

Originally Posted by JohnChen (Post 2763476)
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.

Squirre1 20th April 2011 16:22

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

Afrow UK 20th April 2011 21:57

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

mrphantuan 22nd April 2011 02:05

Firefox 4 is just called MozillaWindowClass.






_________________
noi that fami,noi that 190|


All times are GMT. The time now is 17:41.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.