Click here to Skip to main content
16,021,041 members
Articles / Desktop Programming / Windows Forms
Article

C# - Installing and uninstalling software

Rate me:
Please Sign up or sign in to vote.
2.36/5 (17 votes)
21 Aug 20072 min read 144K   6.6K   29   16
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


Written By
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

 
Questioncan you please provide the C# console code to uninstall codeXDR agent from windows 10? Pin
Member 1179128828-Sep-22 23:05
Member 1179128828-Sep-22 23:05 
QuestionHI Pin
Member 1453925923-Jul-19 8:37
Member 1453925923-Jul-19 8:37 
GeneralMy vote of 4 Pin
mohammed aas20-Nov-12 23:40
mohammed aas20-Nov-12 23:40 
QuestionAdding exe files? Pin
frkngrpnr29-Aug-12 15:40
frkngrpnr29-Aug-12 15:40 
QuestionNeed help in this Pin
HARISH KUMAR JHAMNANI25-May-12 3:14
HARISH KUMAR JHAMNANI25-May-12 3:14 
QuestionHow To UnInstall Applicaion by using C# sample Pin
Narasimha Murthy SR1-Feb-10 19:27
Narasimha Murthy SR1-Feb-10 19:27 
Generalhi Pin
GhoshSandeep2-Aug-09 22:52
GhoshSandeep2-Aug-09 22:52 
QuestionGUID Pin
T0mpika17-Apr-09 5:10
T0mpika17-Apr-09 5:10 
QuestionSofware Engineering Jobs in Arequipa (Peru) Pin
obi11113-Aug-08 23:51
obi11113-Aug-08 23:51 
AnswerRe: Sofware Engineering Jobs in Arequipa (Peru) Pin
Jaime Olivares21-Sep-08 16:57
Jaime Olivares21-Sep-08 16:57 
GeneralUninstall Softwares Pin
pavanip1-Aug-08 1:19
pavanip1-Aug-08 1:19 
GeneralThanks Pin
sheep1312-Jun-08 10:19
sheep1312-Jun-08 10:19 
Generaldid earthquake impact Arequipa Pin
tgueth22-Aug-07 6:12
professionaltgueth22-Aug-07 6:12 
GeneralNo, it doesn't Pin
KronoX22-Aug-07 8:06
KronoX22-Aug-07 8:06 
GeneralRe: No, it doesn't Pin
tgueth22-Aug-07 9:13
professionaltgueth22-Aug-07 9:13 
GeneralThank you :) Pin
KronoX22-Aug-07 9:17
KronoX22-Aug-07 9:17 

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

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