Close/exit a program: Difference between revisions
m (Added code to close "Winamp 3".) |
|||
(One intermediate revision by the same user not shown) | |||
Line 12: | Line 12: | ||
== Example == | == Example == | ||
<highlight-nsis>Push "Winamp v1.x" | <highlight-nsis>Push "Winamp v1.x" | ||
Call CloseProgram</highlight-nsis> | Call un.CloseProgram</highlight-nsis> | ||
This piece of code will close down Winamp 1, 2 or 5. To close Winamp 3, use the following code: | This piece of code will close down Winamp 1, 2 or 5. To close Winamp 3, use the following code: | ||
<highlight-nsis>Push "STUDIO" | <highlight-nsis>Push "STUDIO" | ||
Call CloseProgram</highlight-nsis> | Call un.CloseProgram</highlight-nsis> | ||
To find out other windows' classes ("Winamp v1.x" in Winamp 1/2/5's case) use a program such as [http://www.gena01.com/win32spy/ Win32Spy] (open source). | To find out other windows' classes ("Winamp v1.x" in Winamp 1/2/5's case) use a program such as [http://www.gena01.com/win32spy/ Win32Spy] (open source). | ||
Line 24: | Line 24: | ||
<highlight-nsis>!include WinMessages.nsh | <highlight-nsis>!include WinMessages.nsh | ||
Function CloseProgram | Function un.CloseProgram | ||
Exch $1 | Exch $1 | ||
Push $0 | Push $0 |
Latest revision as of 18:17, 20 November 2009
Author: virtlink (talk, contrib) |
Description
You can close or exit any program by using this code.
This code won't work with all programs, but it will with most of them. If the code doesn't work as it is written here, try uncommenting the 'SendMessage $0 ${WM_DESTROY} 0 0' and comment the 'SendMessage $0 ${WM_CLOSE} 0 0' line. Winamp 2 (and propably Winamp 3 too) can be closed with the 'SendMessage $0 ${WM_CLOSE} 0 0' line.
To use this function push the window's class name and call the function.
Example
Push "Winamp v1.x" Call un.CloseProgram
This piece of code will close down Winamp 1, 2 or 5. To close Winamp 3, use the following code:
Push "STUDIO" Call un.CloseProgram
To find out other windows' classes ("Winamp v1.x" in Winamp 1/2/5's case) use a program such as Win32Spy (open source).
The Function
!include WinMessages.nsh Function un.CloseProgram Exch $1 Push $0 loop: FindWindow $0 $1 IntCmp $0 0 done #SendMessage $0 ${WM_DESTROY} 0 0 SendMessage $0 ${WM_CLOSE} 0 0 Sleep 100 Goto loop done: Pop $0 Pop $1 FunctionEnd
See also the following threads: Windows Messaging and Need "SendMessage"-Command Help