2 min read

Uninstall Hive

Introspecting a machine’s uninstall information is one way to find what the machine currently installs and where it installs it, the install location. If you can uninstall something then you have something installed, surely, logically; see Figure 1. A Windows machine’s registry records how to remove installed programs.

Mind map

Figure 1: Mind map

The example below uses R but the same principle applies to other languages provided that the language equips an interface to the Windows registry access functions.

Registry Hive

The local machine hive registers the local R installation with its version numbers and other interesting pieces of information. Reading the entire key extracts a named list.

is1 <- utils::readRegistry(
  file.path("SOFTWARE", "Microsoft", "Windows", "CurrentVersion", "Uninstall", 
            paste("R for Windows 4.2.1", "is1", sep = "_"), fsep = "\\"), 
  hive = "HLM"
)
DisplayName R for Windows 4.2.1
DisplayVersion 4.2.1
EstimatedSize 170133
HelpLink https://www.r-project.org
Inno Setup CodeFile: HelpStyle HTML
Inno Setup CodeFile: MDISDI MDI
Inno Setup: App Path C:/Program Files/R/R-4.2.1
Inno Setup: Deselected Components
Inno Setup: Deselected Tasks quicklaunchicon
Inno Setup: Icon Group R
Inno Setup: Language en
Inno Setup: Selected Components main,x64,translations
Inno Setup: Selected Tasks desktopicon,recordversion,associate
Inno Setup: Setup Type user
Inno Setup: Setup Version 6.2.0
Inno Setup: User royra
InstallDate 20220628
InstallLocation C:/Program Files/R/R-4.2.1/
MajorVersion 4
MinorVersion 2
NoModify 1
NoRepair 1
Publisher R Core Team
QuietUninstallString “C:/Program Files/R/R-4.2.1/unins000.exe” /SILENT
UninstallString “C:/Program Files/R/R-4.2.1/unins000.exe”
URLInfoAbout https://www.r-project.org
URLUpdateInfo https://www.r-project.org
VersionMajor 4
VersionMinor 2

The install location tells where the program lives on the local machine as a backslash-separated Windows folder path. (Back slashes replaced by forward in the above tabulation.)

is1$InstallLocation
## [1] "C:\\Program Files\\R\\R-4.2.1\\"

All Uninstallables

The R language can find all programs subject to removal. Search for all subkeys found under the local machine’s “software, Windows, current version, uninstall” registry key.

uninstall_key <- function(...)
  file.path("SOFTWARE", "Microsoft", "Windows", "CurrentVersion", "Uninstall",
            ..., fsep = "\\")
uninstall <- utils::readRegistry(uninstall_key(), "HLM")
subkey <- names(uninstall)[uninstall == "<subkey>"]
hive <- lapply(uninstall_key(subkey), utils::readRegistry, "HLM")
names(hive) <- subkey

The resulting hive is a list of lists, one list of properties for every hived uninstallable program.

hive$`R for Windows 4.2.1_is1`$InstallLocation
## [1] "C:\\Program Files\\R\\R-4.2.1\\"

Above gives the install location of R.