-2

What will happen if we try to install a software using powershell which has already installed in a server . For an example I already have notepad++ in my server, Now I try to install same notepad++ version in my server using powershell. Then what will be the output?. Besides, Is there a way that I could find whether a software has already installed in server or not.

  • What will happen depends on the installer type used: legacy setup.exe, MSI installer file, or whatever other installer type you use. Different mechanisms lead to very different behavior. A legacy setup.exe will likely just install on top or side-by-side, barring built-in mechanisms to identify existing installations. MSI has built-in features to detect existing installations and will "know" whether the existing installation is the same version or if it is related by version. Other technologies have other mechanisms. – Stein Åsmul Oct 20 '20 at 15:44

1 Answers1

0

There are many kinds of installers, but most add records in the Add / Remove list of programs, but there are no guarantees. Here is C++ code to scan the registry and check via WMI. You can use scripts instead of course, but it is not an exact science to find what is installed - some installers are very custom and non-standard and follow few guidelines.

Registry Entries:

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

MSI Packages:

For MSI packages there are ways to check whether the exact same version or a related version is installed. If you have the product code of the MSI, you can simply check whether it is installed like this:

Dim installer : Set installer = CreateObject("WindowsInstaller.Installer")
MsgBox installer.ProductState("{00000000-0000-0000-0000-000000000001}") ' <= PRODUCT CODE

Longer sample linked here.

You can find the product code for an installed MSI using several approaches: How can I find the product GUID of an installed MSI setup?

If you have the upgrade code for a family of MSIs you can use the RelatedProducts method to find out whether a related product is installed:

Set installer = CreateObject("WindowsInstaller.Installer")
Set upgrades = installer.RelatedProducts("{UPGRADE-CODE-GUID-HERE}")

For Each u In upgrades
   MsgBox u, vbOKOnly, "Product Code: "
Next

How can I find the Upgrade Code for an installed MSI file?. You can get the upgrade code for an MSI due to be installed by looking in the Property table using Orca.

Pragmatic Approaches:

One option is to identify a key file from each installation and check for its existence using any language you want - scripting will do.

Set fso = CreateObject("Scripting.FileSystemObject")
MsgBox fso.GetFileVersion("C:\Windows\System32\vcruntime140.dll")

The above script snippet from this rant on how to find the installed VCRedist version.


Link:

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140