Thursday, 5 September 2013

Add or Remove programs using C# in Control Panel

In this article, I am going to give steps and code examples to show an entry in Control Panel for installed application and code to remove installed application from Control Panel using C#.

Consider the two C# projects

    1. Setup (Console Application).
    2. MorganApp (Windows Form Application).

You can download source files and binaries from following links  Download exe | Download source

1. Setup (Console Application)- Add or Remove Control Panel programs using C#

   Create new C# Project as Console Application with the name Setup and replace the following code to Register application in Add /Remove programs.

using System;
using Microsoft.Win32;

namespace Setup
    class Program
        static void Main(string[] args)
            string appName = "MorganApp";
            string installLocation = @"C:\MorganTech";
            string displayIcon = @"C:\MorganTech\setup-icon.ico";
            string uninstallString = @"C:\MorganTech\MorganApp.exe";


            Console.WriteLine("Application Installed Successfully....");

        public static void RegisterControlPanelProgram(string appName, string installLocation, string displayicon, string uninstallString)
              string Install_Reg_Loc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";

              RegistryKey hKey = (Registry.LocalMachine).OpenSubKey(Install_Reg_Loc, true);

              RegistryKey appKey = hKey.CreateSubKey(appName);

              appKey.SetValue("DisplayName", (object)appName, RegistryValueKind.String);

              appKey.SetValue("Publisher",(object)"Morgan Tech Space",RegistryValueKind.String);

                       (object)installLocation, RegistryValueKind.ExpandString);

              appKey.SetValue("DisplayIcon", (object)displayicon, RegistryValueKind.String);

                     (object)uninstallString, RegistryValueKind.ExpandString);

              appKey.SetValue("DisplayVersion", (object)"v1.0", RegistryValueKind.String);
            catch (Exception e)
                throw e;

2. MorganApp (Windows Form Application)- Add or Remove Control Panel program in C#

   Create new C# Project as Windows Form Application with the name MorganApp.  Add a Button control and generate the click event for the same.


Now replace the following code to Remove application from Add /Remove programs.

using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace MorganApp
    public partial class MorganApp : Form
        public MorganApp()

        private void btRemove_Click(object sender, EventArgs e)
            MessageBox.Show("Application Removed Successfully", "Morgan App");

        public static void RemoveControlPanelProgram(string apllicationName)
            string InstallerRegLoc = @"Software\Microsoft\Windows\CurrentVersion\Uninstall";
            RegistryKey homeKey = (Registry.LocalMachine).OpenSubKey(InstallerRegLoc, true);
            RegistryKey appSubKey = homeKey.OpenSubKey(apllicationName);
            if (null != appSubKey)

Now follow the below steps to test the sample code.

   1. Build the two projects separately.
Add or Remove control panel programs in C#

   2. Create the folder MorganTech in C# drive. (you can create folder in whatever the location you want and change the install location in the above code correspondingly)

   3. Copy the two exe files Setup.exe and MorganApp.exe from configuration path ( i-\\...Setup\bin\Release, ii-.\\..MorganApp\bin\Release). to the folder MorganTech

   4. Ensure the icon file which you are going to give for control panel program is exist or not. in this case I have placed the icon file setup-icon.ico.

Add or Remove control panel items in C#

    5. Run the Setup.exe, now you have successfully registered this program in Add/Remove control panel items. see the below image
Add or Remove control panel application in C#

 6. Click UnInsall/Change button to remove this program from control panel. You will see the below window. then click Remove button to complete process.

Add or Remove programs using C#

Related Articles:

Show balloon tooltip c#
Get current time on a remote system using C# 
Convert DateTime to Ticks and Ticks to DateTime in C#
Convert Object To Byte Array and Byte Array to Object in C#
How to read data from csv file in c# 
Bulk Insert into SQL Server using SqlBulkCopy in C#
Import CSV File Into SQL Server Using SQL Bulk Copy

Software Developer



  1. thank you very much Mrogan

  2. My family members all the time say that I am wasting my time here
    at web, however I know I am getting experience daily by
    reading thes nice posts.

  3. Thank you very much. A very kind behavior to share your knowledge

  4. Thank you! I've been struggling on this for months...

  5. Thanks its resolve my problem