Archive: Close Running Application


Close Running Application
  i remember the FindWindow command in NSIS 1.4x could detect if a software was running during the installation-process and close it.

now that the commands changed, i'm in need of help.

i want my setup to

1) detect if winamp is running and force the user to close it

or

2) close winamp without asking

if you can help me, please paste the syntax. the makensis.html wasnt a big help for me!

thx in advance,

kb


This is from functions.htm in the nsis distro:


CloseWinamp

Push$0
loop:
FindWindow $0 "Winamp v1.x"
IntCmp $0 0 done
SendMessage$0 16 0 0
Sleep 100
Goto loop
done:
Pop $0
FunctionEnd
>

i remember i tried this before. nothing happening. reading the makensis.html it should be possible with FindWindow/SendMessage, but i have no clue how that works. this function does nothing, but thanks anyhow for the quick reply!


I just ran it and it closed winamp just like it should. Are you calling the function?


i did copy+paste =)

what version of nsis did you use? mine is 1.94


I'm using 1.94


Name "CloseWinamp"

>Outfile "closewinamp.exe"

>Section -
Call CloseWinamp
SectionEnd

>Function CloseWinamp
Push$0
loop:
FindWindow $0 "Winamp v1.x"
IntCmp $0 0 done
SendMessage$0 16 0 0
Sleep 100
Goto loop
done:
Pop $0
FunctionEnd
>

This will not work for the current BETA of Winamp. If you want to close a BETA version simply replace

FindWindow*$0*"Winamp*v1.x"

with
FindWindow $0 "STUDIO"


~ Florian

Doh. It never crossed my mind they might be refering wo Winamp 3. :cool:


thank you very much! works now, and i added both functions to support both versions =)


Excuse my ignorance on this topic, but how do you find out the name of the Window you want to close if you did not write the application you are trying to close?

-Carlos


Carlos,
there is a tool called Spy++ that ships with Visual Studio. With this tool you could identify the window class or window handle of every open window.
There are similar tools called Window Finder (which ships with source code) and WinSpy.

Kichik uploaded the Spy program from the platform SDK at this thread.

~ Florian


Thank you for all those useful links Florian, they worked great!!!

-Carlos


kill task
  is there an other way to close apps like the above one
i mean a command like kill (killtask ...)"exename"
is more simplier than write everytime a function like the findwindow...
is there a way to implement this command in the next releases of nsis

sorry for my bad english:confused:


Just make a function to do that an always pass in "exename" in one of thhe registers. Name the function "killtask" if you want, then just Call killtask


example
  can you give me an example please???:hang:



CloseApplication

Pop$1
Push$0
loop:
FindWindow $0 $1
IntCmp$0 0 done
SendMessage$0 16 0 0
Sleep 100
Goto loop
done:
Pop $0
FunctionEnd

>Function .onInit
Push "Winamp v1.x"
Call CloseApplication
FunctionEnd
>
Push the class name of the application before calling it, then the closeapplication will close it.

ah
  ah yes ok thank you :) :) :)


no
  that way wont work because the task i want to close runs in the background
i have found the window name but it close only the (invisible) window and not the task
the task is still shown in taskmon

is there an other way to close this because i can not write over the file

please help :confused: :confused:


please Tell me!! help me!!
  I can not English Very well.

I want to closeing MYSQL daemon.
please Tell me. help.

Function CloseWinamp
Push $0
loop:
FindWindow $0 "Winamp v1.x" <== How Can i set...
IntCmp $0 0 done
SendMessage $0 16 0 0
Sleep 100
Goto loop
done:
Pop $0


In case of MySQL, you can NOT simply kill the daemon. If you do that, you will probably loose database consitency. Instead, simply run the mysqladmin commandline-tool:

C:\mysql\bin\mysqladmin shutdown

This terminates the server gracefully.

From within your script, this would be:


stopMySQL

ExecWait "C:\\mysql\\bin\\mysqladmin shutdown"
>FunctionEnd
>
Note:
Depending on your setup, this probably needs to specify a database admin-user and his password on the commandline.
See mysql docs...

A question:
Why do you want to shutdown the DB-server?
Nearly anything can be done without shutting down MySQL.

-Fritz

Just, I want to Know... Mysql Daemon State.
  How do i know... MySQL Daemon State. (RUNning? OR Not RUNning)

If (MySQL daemon == running) Sending SQL query To MySQL server.
else message "Please Running MySQL Daemon"


<= please teach me. help me.
How can i know MySQL Daemon State.


Re: ah
 

Originally posted by benp
that way wont work because the task i want to close runs in the background
i have found the window name but it close only the (invisible) window and not the task
the task is still shown in taskmon

is there an other way to close this because i can not write over the file
yes that is true.
it is March, did you find a way to cloes the running task?:)
thank you