Click here to Skip to main content
Click here to Skip to main content

C# - Installing and uninstalling software

, 21 Aug 2007
Rate this:
Please Sign up or sign in to vote.
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... Smile | :)

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

Share

About the Author

KronoX
Web Developer
Peru Peru
I was born in Arequipa-Peru, and lived here almost all my life...
 
Studied Systems engineering at the Catholic University of Santa Maria, and now I'm trying to get more knowledges.
 
My goal is to help people and make them know GOD, to make HIM their best friend. Also I want to do a great job in my life, and to dedicate it to GOD always.

Comments and Discussions

 
GeneralMy vote of 4 Pingroupmohammed aas20-Nov-12 23:40 
QuestionAdding exe files? Pinmemberfrkngrpnr29-Aug-12 15:40 
QuestionNeed help in this PinmemberHARISH KUMAR JHAMNANI25-May-12 3:14 
QuestionHow To UnInstall Applicaion by using C# sample PinmemberNarasimhamurthy.sr1-Feb-10 19:27 
Generalhi Pinmemberrajainmicrosoft2-Aug-09 22:52 
QuestionGUID PinmemberT0mpika17-Apr-09 5:10 
GeneralUninstall Softwares Pinmemberpavanip1-Aug-08 1:19 
GeneralThanks Pinmembersheep1312-Jun-08 10:19 
Generaldid earthquake impact Arequipa Pinmembertgueth22-Aug-07 6:12 
GeneralNo, it doesn't PinmemberKronoX22-Aug-07 8:06 
GeneralRe: No, it doesn't Pinmembertgueth22-Aug-07 9:13 
GeneralThank you :) PinmemberKronoX22-Aug-07 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 22 Aug 2007
Article Copyright 2007 by KronoX
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid