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

C# - Installing and uninstalling software

By , 21 Aug 2007
 

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

About the Author

KronoX
Web Developer
Peru Peru
Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 4groupmohammed aas20 Nov '12 - 23:40 
QuestionAdding exe files?memberfrkngrpnr29 Aug '12 - 15:40 
QuestionNeed help in thismemberHARISH KUMAR JHAMNANI25 May '12 - 3:14 
QuestionHow To UnInstall Applicaion by using C# samplememberNarasimhamurthy.sr1 Feb '10 - 19:27 
Generalhimemberrajainmicrosoft2 Aug '09 - 22:52 
QuestionGUIDmemberT0mpika17 Apr '09 - 5:10 
QuestionSofware Engineering Jobs in Arequipa (Peru)memberobi11113 Aug '08 - 23:51 
AnswerRe: Sofware Engineering Jobs in Arequipa (Peru)memberJaime Olivares21 Sep '08 - 16:57 
GeneralUninstall Softwaresmemberpavanip1 Aug '08 - 1:19 
GeneralThanksmembersheep1312 Jun '08 - 10:19 
Generaldid earthquake impact Arequipamembertgueth22 Aug '07 - 6:12 
GeneralNo, it doesn'tmemberKronoX22 Aug '07 - 8:06 
GeneralRe: No, it doesn'tmembertgueth22 Aug '07 - 9:13 
GeneralThank you :)memberKronoX22 Aug '07 - 9:17 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 22 Aug 2007
Article Copyright 2007 by KronoX
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid