Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Detecting and closing a running application


2 replies to this topic

eheimfeld

eheimfeld
  • Members
  • 10 posts

Posted 13 November 2001 - 16:39

I would like to run a CA that would run prior to InstallValidate that would detect if a specific application is running and close it if it is running.

My installation is being spawned by another application which needs to be updated during the installation. This is a "Catch 22" situation since this application is running in the background while the Installer is trying to overwirte it, so the InstallValidate displays the FilesInUse dialog. The problem with the FilesInUse dialog is that since this application doesn't have a UI the user won't know how to close it; requiring them to press Ctrl+Alt+Del is something too advanced for most of our users. I can instruct them to click ignore but then when the PC finished rebooting the exe's name is meesed up since the name of the applicaiton has 9 characters not 8.

So, the best solution I can think of is that early on in the installtion I will detect the fact that this application is running and I will close it programatically within this CA. The question is how to do it? Does InstallScript have a function for this? Do I need to call a function in the standard Win32 API, and which one(s)?

I am using ISWI 2.03.


Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 13 November 2001 - 16:49

Win32

Use FindWindow to get the handle for the main window of the application you want to find then call PostMessage to send a WM_CLOSE message to  shut your application down.

A C CA would be something like this.  But I am sure you could do it in InstallScript

UINT __stdcall CloseMyProg(MSIHANDLE hInstaller)
{
HWND hWnd;
hWnd = FindWindow("MYCLASSNAMEorNULL", "MYWINDOWNAMEorNULL");

if (hWnd) PostMessage(hWnd, WM_CLOSE, 0 , 0);
return ERROR_SUCCESS;
}

(Edited by Ian Blake at 4:03 pm on Nov. 13, 2001)


eheimfeld

eheimfeld
  • Members
  • 10 posts

Posted 13 November 2001 - 19:22

Hi Ian,

Thanks for your reply, it worked exactly as I wanted it.

Now FYI, I did it with InstallScript without any Win32 (it's quite similar to your code), this is my code:
#define WM_CLOSE 16

function KillApp(hMSI)
   //NUMBER nMsg, nwParam, nlParam;
   HWND nHwnd;
begin

   // Retrieve the handle of the AbwUpdate window. If it returns with a
   // non-null handle use SendMessage to close it.
   nHwnd = FindWindow ("", "AutoUpdate");
   SendMessage (nHwnd, WM_CLOSE, 0, 0);

end;