Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

C# - Installing and uninstalling software

0.00/5 (No votes)
21 Aug 2007 1  
This article will teach you how to install and uninstall *.msi files with C#

Introduction

Hi everybody... this is my first article, and I know that this is so easy to do, but I was looking for this in the site, and I did not find it, so I decide to do it and post it too. I'm happy to share this with you.

This article will teach us how to install and uninstall "*.msi" files (setup) with Visual C# 2005.

Screenshot - Installer.jpg

Background

Obviously, this program is not usefull because we have to manage it, but I post it for you, just to watch the code, I'll use it for the mobile agent I'm doing, so it will perform this action bye itself, and no one will note this.

Using the code

This program is so easy... so I am not going to make you waste time explaining how to do it step by step, because I just make it visual so you could prove it.

There are some things that we must know "msiexec.exe" is a component of "Windows Installer" used to install, uninstall and repair software in "*.msi".

There are many options to manipulate the process, but we are just going to talk about two of them:

  1. Setup Options (Typed before the path of your *.msi file)
  • To install you just have to type "/i".
  • To uninstall you just have to type "/x".
  • To repair you just have to type "/f".

2. Screen Options (Typed after the path of your *.msi file)

  • If you don't want to display a user interface "/qn".
  • To display a reduced user interface with a modal dialog box displayed at the end of the installation "/qb".
  • To display the full user interface with a modal dialog box displayed at the end "/qr".
  • To display no user interface, except for a modal dialog box displayed at the end "/qf".

To know more about them, go to the next website: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/msiexec.mspx?mfr=true

Or just go to the execute dialog and type "msiexec", then click "Acept", and a dialog with all the information will appear to you.

Firstable, we are going to use System.Diagnostics, so you will have to add this.

using System.Diagnostics;

The code to install software without user interface is:

private void installSoftware() 
{ 
    Process p = new Process(); 
    p.StartInfo.FileName = "msiexec.exe"; 
    p.StartInfo.Arguments = "/i \"C:\\Application.msi\"/qn"; 
    p.Start(); 
}

The code to uninstall software without user interface is:

private void uninstallSoftware() 
{ 
    Process p = new Process(); 
    p.StartInfo.FileName = "msiexec.exe"; 
    p.StartInfo.Arguments = "/x \"C:\\Application.msi\"/qn"; 
    p.Start(); 
}

The code to repair software without user interface is:

private void repairSoftware() 
{ 
    Process p = new Process(); 
    p.StartInfo.FileName = "msiexec.exe"; 
    p.StartInfo.Arguments = "/f \"C:\\Application.msi\"/qn"; 
    p.Start(); 
}

Well this is all, I hope this to help someone in the future. My special thanks the following website: http://www.stratos-ad.com/forums3, people there are really friendly and helped me to perform the code.

Points of Interest

I am really interested on automating the most posible the processes of a computer.

History

Well there's no history jet... :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here