Check if the application is already installed

c#
13,159

Solution 1

I'm not sure on how to do this specifically with C#, but while using the Nullsoft Installer this is the approach I've seen used: before installing, check for a registry key that is created during the install.

Uninstallers show up in the Add/Remove Programs control panel. The list of the uninstallers is stored under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall. If the installer registers an uninstaller, the uninstaller's key is a good key for the installer to check for, because:

  1. Assuming the program is being installed for all users, the key tested for must be under HKey Local Machine (HKLM) not a key specific to the current user (HKey Current User). The uninstaller's key is under HKLM

  2. Sometimes multiple versions of the same program need to be installed side-by-side. Uninstaller keys should be specific to each version, so rules can be added to check the installer's version number against installed versions.

There is a limitation with checking for registry keys to tell if a program is installed: if the program is deleted out of Program Files by hand (without using the uninstaller), reinstalling will fail. To avoid this problem, after finding the uninstaller registry key, the installer can check that the uninstaller program still exists. If it does, it's probably safe to assume the program is still installed.

While playing with installers and conditional installation, it's worth keeping in mind that sometimes reinstalling is useful for cleaning up problems. It can be tedious to be forced to walk through a (troublesome) uninstall to be able to reinstall.

See NSIS's page on Add/Remove Programs for more details on uninstall registry keys.

Solution 2

Put an entry in the registry on install. If, when the installer runs, the entry is there, then the program is already installed (or your user has hacked the registry to make the installer think it has been). If it's not, then you haven't installed it yet.

Share:
13,159

Related videos on Youtube

Jon Limjap
Author by

Jon Limjap

Principal Developer at PageUp. Mainly doing C#/.NET, but also did some iOS/Objective-C and Java/GWT in a previous life. Trying to learn TypeScript/JavaScript. Focusing on distributed systems nowadays. Microsoft MVP from 2009-2018, latest for Visual Studio & Development Technologies. I also lead the Philippine .NET Users Group(PHINUG).

Updated on April 23, 2022

Comments

  • Jon Limjap
    Jon Limjap about 2 years

    I want to check if an app is alredy installed through launch conditions.If yes i want to exit the installer,if no the installation should continue.Could anyone tell how to achive this in c# installer?.

    Regards, Harsh Suman