Reputation: 51
I need to detect 2 conditions before installing and application using an installer created with visual studio 2010.
Detect an existing application
I need to not allow an app to install unless another application is already install. For example if MS Office is not installed on the PC alert the user and abort the install.
Detect an assembly installed in the GAC
I also need to at check to see if an assembly is in the GAC. Checking if a specific version or higher is in the GAC would ideal.
I do not want to include the assembly or install the prerequisite. I just need to verify if it is installed and if not alert the user and abort the install.
Upvotes: 3
Views: 1731
Reputation: 52675
The best way to handle this situation is to use launch conditions
You can open the launch condition editor by right-clicking on your Setup Project and selecting
View->Launch Conditions
Detect an existing application
One way to detect an existing application you can set up a Registry Search and Launch Condition (Right click Search Target Machine -> Add Registry Search)
The properties for the Registry search for office 10 might be
Name: Search for Office 10
Property: OFFICE10REGISTRY
RegKey: SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot
Root: vsdrrHKLM
Value: Path
Then you can add launch condition of with these properties
Name: Office Installed Condition
Condition: OFFICE10REGISTRY
Message: Office 10 not detected
If you want to search for any Office version you can create several registry searches and then use the condition of OFFICE10REGISTRY OR OFFICE11REGISTRY OR OFFICE12REGISTRY
.
Detect an assembly installed in the GAC
This time you add a File search to search for the installed file in the gac.
Name:Search for Assembly In GAC
Depth: 5
FileName: Microsoft.JScript.dll
Folder: [WindowsFolder]\assembly\GAC\Microsoft.JScript
MaxVersion: 8
MinVersion: 7
Property: JSCRIPTEXISTS
Note that file name is the dll and the folder follow the pattern of the namespace. Also note you can specify just the min versions if you want.
Then adding a Launch Condition
Name: Assembly Gac Condtion
Condition: JSCRIPTEXISTS
Message: Missing JScript
When you're done the end result might look like this
Upvotes: 6
Reputation: 1269
Since you need to do 2 checks, I would recommend that you write a custome install step by deriving Installer class(http://msdn.microsoft.com/en-us/library/79e7ka7s(v=vs.100).aspx)
Here you should override OnBeforeInstall method and code your logic to check
if either of the check fails, you can throw and exception and installation will stop.
For prereq app, i would recommend that you check the registry hive. Windows creates a registry entry for each installed application.
For GAC check, I would recommend that you try loading the assembly reflectively without specifying the path. If the assembly loads, its safe to assume that its in GAC
Hope this helps
Cheers, DK
Upvotes: 0