Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically registering program into Add/Remove programs and storing files within an executable

Tags:

I am working on a windows c# console application which I want to allow the user to install on to their computer.

I want to make my own Windows Installer executable as the Setup Deployment tools built into Visual Studio, appear to be somewhat lacking in functionality for customisations and documentation.

Therefore, because I want to make my own Windows installer, how do I register my program into the Add/Remove Programs window so they can choose to uninstall it again if they wish and it relaunches my installer program to do the removal.

Also as well, the executable would obviously need to copy the files into various locations on the PC, i.e. C:\Program Files so how would I store the executable files within the windows installer executable so I can move them into the right location.

Is this possible to do?

Thanks for any help you can provide.

like image 846
Boardy Avatar asked Aug 05 '12 20:08

Boardy


People also ask

How do I remove Programs from applications and features?

In the search box on the taskbar, type Control Panel and select it from the results. Select Programs > Programs and Features. Press and hold (or right-click) on the program you want to remove and select Uninstall or Uninstall/Change. Then follow the directions on the screen.

How do I disable ARP Add Remove Programs entry during the installation through property?

When the property is set to 1, these entries are not written in the registry and hence, do not appear in the Control Panel Add/remove applet. Also, setting ARPNOREMOVE property to 1 will just disable the remove button from Add/remove Programs.

How do I remove a program from the add/remove list?

If the program list is not correct in Add/Remove Programs, you can double-click the Uninstall. reg file on your desktop to restore the original list of programs in the registry. If the program list is correct in Add/Remove Programs, you can right-click the Uninstall. reg file on your desktop, and then click Delete.

How to Uninstall program from Control Panel using c#?

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


1 Answers

Here's a routine we use to register our program in Add/Remove Programs:

private void CreateUninstaller()
{
    using (RegistryKey parent = Registry.LocalMachine.OpenSubKey(
                 @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true))
    {
        if (parent == null)
        {
            throw new Exception("Uninstall registry key not found.");
        }
        try
        {
            RegistryKey key = null;

            try
            {
                string guidText = UninstallGuid.ToString("B");
                key = parent.OpenSubKey(guidText, true) ??
                      parent.CreateSubKey(guidText);

                if (key == null)
                {
                    throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", UninstallRegKeyPath, guidText));
                }

                Assembly asm = GetType().Assembly;
                Version v = asm.GetName().Version;
                string exe = "\"" + asm.CodeBase.Substring(8).Replace("/", "\\\\") + "\"";

                key.SetValue("DisplayName", "My Program");
                key.SetValue("ApplicationVersion", v.ToString());
                key.SetValue("Publisher", "My Company");
                key.SetValue("DisplayIcon", exe);
                key.SetValue("DisplayVersion", v.ToString(2));
                key.SetValue("URLInfoAbout", "http://www.blinemedical.com");
                key.SetValue("Contact", "[email protected]");
                key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
                key.SetValue("UninstallString", exe + " /uninstallprompt");
            }
            finally
            {
                if (key != null)
                {
                    key.Close();
                }
            }
        }
        catch (Exception ex)
        {
            throw new Exception(
                "An error occurred writing uninstall information to the registry.  The service is fully installed but can only be uninstalled manually through the command line.",
                ex);
        }
    }
}
like image 122
Samuel Neff Avatar answered Nov 02 '22 04:11

Samuel Neff