Skip to content
⌘ NSIS Forum Archive

Closing Running Applications

5 posts

[FAIL]Pagannn#

Closing Running Applications

I have come up with a way to get rid of running applications during the install process. I know NSIS has the SendMessage function that you can use, but sometimes it doesn't work.

I was trying to shut down Microsoft Outlook with the SendMessage function and it wouldn't close when minimized. I tried it on several machines and the dinosaur known as Windows NT won't allow SendMessage to close a minimized window. Windows 2000 and XP work just fine.

I wrote a little command line app that takes the window class as a parameter and uses it to set the application window to "normal" mode and then close it.

You can download it here:



I also included a cool little utility that allows you to find the class of a window.

Enjoy!
nocarr#
Re: Closing Running Applications

Originally posted by [FAIL]Pagannn
I have come up with a way to get rid of running applications during the install process. I know NSIS has the SendMessage function that you can use, but sometimes it doesn't work.
................
You are delphi programmer, right? 😁
Why not try this, it produces 14k code, instead of 20k.

program stopper;

uses
windows;

Var hwnd: Integer;
begin
hwnd := FindWindow(pchar(paramstr(1)),Nil);
If Hwnd <> 0 Then PostMessage(hwnd, 18, 0, 0);
end.

And then in the .nsi file use the Class of the program to close as parameter instead of it's handle.

P.S. UPXed, the size is 8,5k (8704b)
[FAIL]Pagannn#
Minor Issue

First off, I haven't touched Delphi in many years. While I agree that it is superior to the MS bastardization of C++, the market in my area just isn't there.

The code you put up works well, but I don't see that it restores the window to SW_NORMAL before sending the WM_CLOSE message. Because of my time away from Delphi, I might not be remembering the "SendMessage" wrapper paramters.

I could get the exe file smaller if I remove this as well as the command line response strings.

But thanks for the response! I'll look for other ways to get the exe file downsized.
Repzilon#
You can also modify CloseWinamp Function and get a lower overhead.

;------------------------------------------------------------------------------
; CloseWinamp
;
; Closes all running instances of Winamp 1.x/2.x
;
; modifies no other variables
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
What is the class name of Outlook ? Anybody with Spy++ and Outlook (I don't use the latter, so I did not install it) is welcome to tell us.