Calling msiexec.exe on Uninstall - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

AlexSkylink
Posts: 7
Joined: Thu Jul 07, 2011 10:54 pm

Calling msiexec.exe on Uninstall

On application Uninstall I need to remove all the msi files that I have in a folder. Currently I have a custom action that calls an executable and it goes throw all the msi files in that directory and starts a new Process to remove each msi. When i do this, I see the console window of my executable but when I check the control panel, it does not remove those msi's.

Any idea on how I can perform these application removal during my Uninstall?


Here is what's done in the executable:
foreach (string updaterFile in Directory.GetFiles(updatesDirectory))
{
try
{
string args = string.Format("/x \"{0}\" /passive", updaterFile);
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
WorkingDirectory = Environment.SystemDirectory,
FileName = "msiexec.exe",
Arguments = args,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Normal
};
process.Start();
process.WaitForExit();
}
catch(Exception ex)
{
throw new Exception("ERROR: " + ex.Message);
}
}
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Calling msiexec.exe on Uninstall

Hi,

Please note that Windows Installer does allow multiple install/uninstall processes to run at the same time. This means that you will have to
launch your custom action on the UI sequence from the Uninstall, i.e. before you select "Remove" button.

If your package is uninstalled with basic UI then you don't have and UI sequence. In this case you can schedule your custom action under InstallFinalize standard action,
as asynchronous, do not wait for return.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
AlexSkylink
Posts: 7
Joined: Thu Jul 07, 2011 10:54 pm

Re: Calling msiexec.exe on Uninstall

I tried adding InstallFinalize and it still doesn't work. I've attached a screenshot of what my Custom Actions page look like.
I might not doing this correctly.
Attachments
Untitled.png
Untitled.png (77.53 KiB) Viewed 7983 times
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Calling msiexec.exe on Uninstall

Hello,

Here is what Bogdan advised you can try to achieve the intended functionality:
Full UI
- add the custom action as an UI Custom Action( Custom Actions page )
- set a DoAction event that executes it( Dialogs page ) to be published from a control before the user can click the Remove button( MaintenanceTypeDlg )
http://www.advancedinstaller.com/user-g ... te-ca.html

Basic UI
- add the custom action after the InstallFinalize standard action from the Custom Actions page set with "Asynchronous, do not wait for return"
- set its execution condition to:

Code: Select all

REMOVE="ALL"
- do not move the InstallFinalize standard action after the Uninstall standard action like you did
http://www.advancedinstaller.com/user-g ... ation.html

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
AlexSkylink
Posts: 7
Joined: Thu Jul 07, 2011 10:54 pm

Re: Calling msiexec.exe on Uninstall

I tried both ways (Full UI and Basic UI) and neither one worked.
I'm able to do this with Visual Studio Installer project easily by calling my executable in OnAfterUninstall method and it launches a new process. This new process (executable) waits untill the main msi uninstall is done, it will then start running the executable.
In this executable, I go through a folder that has many msi files and I uninstall them one by one. That's why this has to be done when the main msi is completed since microsoft does not support running two msi at same time.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Calling msiexec.exe on Uninstall

Hi,

I attached two samples, one runs the custom action, in my example Notepad.exe, with impersonation, i.e. it will run with admin
rights under the SYSTEM account. The other project will execute the custom action as immediate, under the current user.

In both projects you need to change the "Source Path" field for pointing to your EXE.

To one I suspect you need is the first one, i.e. with impersonation, as it makes changes to the system, but I attached both samples to cover
all possible scenarios you might have.

Regards,
Bogdan
Attachments
sample - Immediate execution.aip
(10.2 KiB) Downloaded 550 times
sample - with impersonation.aip
(10.2 KiB) Downloaded 541 times
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”