Do not delete Files in “C:\Windows\installer” On SharePoint Servers!
Never delete the Install cache folder %windir%\installer to free up some disk space. This will cause serious problems during service pack upgrades!
In one of my cases, It happened. The installer folder was deleted and when I tried installing Service pack 2, It scolded me with this error: “The detection failed, this can be due to a corrupted installation database.”
Workaround is: I copied the files inside Installer cache from other SharePoint server and ran the upgrade again. It worked!
Update: Found this article to collect the Install cache from other servers and update the failed server:
https://social.technet.microsoft.com/Forums/en/sharepointadmin/thread/cfa66cd3-2aa2-44ee-9393-ffae41d4f70c
You can use the PowerShell script “Restore-InstallerFiles.ps1” which is capable to scan for the missing files, and to restore them from different sources such as local folder, shared folder or another machine which can be accessed from the target machine.
https://ahmad.jempress.com/post/restore-the-missing-windows-installer-cache-files
https://gallery.technet.microsoft.com/scriptcenter/Restore-the-Missing-d11de3a1