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:\MorganTechsetup-icon.ico"; string uninstallString = @"C:\MorganTechMorganApp.exe"; RegisterControlPanelProgram(appName,installLocation,displayIcon,uninstallString); Console.WriteLine("Application Installed Successfully...."); Console.ReadLine(); } public static void RegisterControlPanelProgram(string appName, string installLocation, string displayicon, string uninstallString) { try { string Install_Reg_Loc = @"SoftwareMicrosoftWindowsCurrentVersionUninstall"; 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); appKey.SetValue("InstallLocation", (object)installLocation, RegistryValueKind.ExpandString); appKey.SetValue("DisplayIcon", (object)displayicon, RegistryValueKind.String); appKey.SetValue("UninstallString", (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() { InitializeComponent(); } private void btRemove_Click(object sender, EventArgs e) { RemoveControlPanelProgram("MorganApp"); MessageBox.Show("Application Removed Successfully", "Morgan App"); this.Close(); } public static void RemoveControlPanelProgram(string apllicationName) { string InstallerRegLoc = @"SoftwareMicrosoftWindowsCurrentVersionUninstall"; RegistryKey homeKey = (Registry.LocalMachine).OpenSubKey(InstallerRegLoc, true); RegistryKey appSubKey = homeKey.OpenSubKey(apllicationName); if (null != appSubKey) { homeKey.DeleteSubKey(apllicationName); } } } }
1. Build the two projects separately.
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-…SetupbinRelease, ii-…MorganAppbinRelease). 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.
5. Run the Setup.exe, now you have successfully registered this program in Add/Remove control panel items. see the below image
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.
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
Thanks,
Morgan
Software Developer
Thank you!
thank you very much Mrogan
Thanks!
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.
Thank you very much. A very kind behavior to share your knowledge
Thank you! I've been struggling on this for months…
Thanks its resolve my problem