How to ensure devenv.exe is not running when my msi is installed
-
22-08-2019 - |
Question
I am writing a VSPackage for Visual Studio 2008, and am deploying it with a WiX generated Msi. As the end of the install, I am running "devenv.exe /setup" as required to get VS to notice my package. However, this command will not succeed if there are any copies of Visual Studio running.
Currently, I tell people they have to close all copies of Visual Studio before installing, but I would prefer it be foolproof. How can I check when someone runs my .msi if any copies of Visual Studio (devenv.exe) are running, and block them from installing my project?
Solution
The WiX toolset has a CloseApps CustomAction that will close windows for you. It unfortuantely does not prompt with a list to close all the applications but the code would be a reasonable place to start.
OTHER TIPS
while(devenvIsRunning()) {} //in main routine of Installer class
static bool devenvIsRunning() //uses this subroutine
{
Process[] procList = Process.GetProcesses();
foreach (Process p in procList)
{
if (p.ProcessName == "devenv")
{
MessageBox.Show("An instance of Visual Studio is still running.\nPlease close all open instances of Visual Studio before continuing.");
return true;
}
}
return false;
}
your best bet is to follow Rob's advide and put together a custom action to check if the process is running. I'd probably do something like see if it's running, try to close, if it's still running then schedule a reboot and do the devenv setup via the RunOnce registry key.
If that's too much work then a bit of an ugly hack would be to use the windows command TASKKILL
to exit the application. Not foolproof but it's better than nothing.
TASKKILL /IM devenv.exe
You can create an installer class in your project and let it enumerate Running Processes