This is something I implemented in my installer and I'm willing to share it
with the community. Basically I did it using a custom action. Here's the
relevant pieces from my .wxs file:

  <Product Id=......>

    <Binary Id="CloseDevenvPrompt"
SourceFile="$(var.ArtOfTest.PromptCloseDevenv.TargetDir)ArtOfTest.PromptClos
eDevenv.CA.dll" />
    <CustomAction Id="CA.CloseDevenvPrompt" BinaryKey="CloseDevenvPrompt"
DllEntry="CloseDevenvPrompt" />

    <InstallExecuteSequence>
      <Custom Action="CA.CloseDevenvPrompt" After="CostFinalize">
        <![CDATA[RUNDEVENV = "1"]]>
      </Custom>
    </InstallExecuteSequence>

The RUNDEVENV variable allows me to control from the command line whether or
not the prompt is activated (and a one other action not relevant to this
discussion). If the user enters "msiexec /i installer.msi RUNDEVENV=0" then
the CA doesn't even run.

The binary file is a very simple C# program. The main file is this:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Deployment.WindowsInstaller;
using System.Windows.Forms;

namespace ArtOfTest.PromptCloseDevenv
{
    public class CustomActions
    {
        static ClosePrompt closeDialog;
        [CustomAction]
        public static ActionResult CloseDevenvPrompt(Session session)
        {
            session.Log("Begin PromptToCloseDevenv");
            while (devenvIsRunning())
            {
                if (null == closeDialog)
                {
                    closeDialog = new ClosePrompt();
                    closeDialog.Show();
                }
                Application.DoEvents();
                Thread.Sleep(100);
            }
            if (null != closeDialog)
            {
                closeDialog.Hide();
                closeDialog = null;
            }
            session.Log("End PromptToCloseDevenv");
            return ActionResult.Success;
        }
        static bool devenvIsRunning()
        {
            Process[] procList = Process.GetProcesses();
            foreach (Process p in procList)
            {
                if (p.ProcessName == "devenv")
                {
                    return true;
                }
            }
            return false;
        }
    }
}

The ClosePrompt class referenced in the above code is a very quick and
simple WinForms dialog written in C#.

In the end the sequence goes like this:

1) User launches installer
2) User selects the features and location to install
3) User clicks Install
4) CA kicks in and immediately shows a "Please close all instances of Visual
Studio" dialog
5) CA periodically checks (every 100 milliseconds) to see if Visual Studio
is still running. If it is, it sleeps for another 100 milliseconds.
6) When the CA recognizes that Visual Studio is no longer running, the CA
exits and installation continues. If Visual Studio was not running at the
start, the dialog doesn't even get displayed. The CA almost immediately
exists.

Hope that helps,
Cody


-----Original Message-----
From: s...@pacaccess.com [mailto:s...@pacaccess.com] 
Sent: Tuesday, March 09, 2010 6:59 PM
To: wix-users@lists.sourceforge.net
Subject: [WiX-users] Preventing install if application is running

I wish to add a feature to my installer which detects if a certain
application is running, and then presents the user with a message asking
them to quit all instances of the application or abort installation.  I'm
new to wix development, but I've searched on this subject and although
I've seen a few messages asking about this type of functionality, I
haven't seen any finished solutions on how to do this so I have a few
questions:

-Some of the postings I've read have said that in v2 a custom action was
needed, but in v3 there is something like this built in.  If so, what is
it?  I haven't been able to find it.  Is there something like this built
into v3?  (That's the version I'm using)

-If there isn't anything which checks for running applications already
built into wix v3.0, I can write my own custom action, but before I do,
has anyone already written a 'check for running application' custom
application?  If there is I don't want to reinvent the wheel.

-I'm new to wix but I have read the docs (or at least some of them).  It
seems like what I'm trying to do would fall into the "standard custom
action" category, yet I don't see anything listed on the standard custom
actions page
(http://wix.sourceforge.net/manual-wix3/standard_customactions.htm).

If anyone can suggest some tips on where to look, I'd appreciate it.  If I
can't find anything I'll write my own custom action, but if something like
this already exists I'd prefer to use something that already works.

Thanks,

Jeff




----------------------------------------------------------------------------
--
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to