ServiceInstallers Part III: Check MSMQ presence during install

by Grank August 22, 2008 14:56
(Part 3 of a 4-part series of tips and tricks for installers for win32 services in .NET.) 
 
So, in the previous post we created and set permissions on a message queue if it didn't already exist.
What if Message Queuing isn't an installed component on the target machine, which it isn't by default?
...well I actually don't know for sure, I never tried.  But I'd be stunned if it didn't explode, we'd expect it to do so.
So we need to not let it try to do this step at all, and inform the user that they need to install MSMQ first.
Fortunately, this is also easy.
Visual Studio's Setup projects have a screen called Launch Conditions, where you can set up a number of types of things to check before the MSI runs into the body of your project's installer, and abort on them if they fail.
Now, MSMQ, if installed, will have added registry values indicating which features are present:
 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\Setup
  • msmq_Core
  • msmq_LocalStorage
  • msmq_HTTPSupport
  • msmq_RoutingSupport
  • msmq_MQDSService
  • etc etc etc...

These entries all have a DWORD of 1, but if MSMQ isn't installed, they won't even be present at all.  The registry key will be there but there will be no values inside it.  If MSMQ is installed, but particular components of it are not, the registry values present would reflect this and we could check for each one, but for our purposes, the Core will do fine as WCF will be handling everything else.

So if you right-click on your Setup project in Solution Explorer and head over to your Launch Conditions window, you'll probably see a .NET Framework Launch Condition, as it will have been detected as a dependency and automatically added.  We want to right-click on Requirements on Target Machine, and select "Add Registry Launch Condition".  We'll see a new entry appear under Search Target Machine, and a new condition appear under Launch Conditions.  We need to go to the properties of the Search item and set things up like so:

(name)
Search for MSMQ
Property
MSMQPRESENT
RegKey
SOFTWARE\Microsoft\MSMQ\Setup
Root
vsdrrHKLM
Value
msmq_Core

And then we'll set up our Launch Condition's properties like this:

(name)
Message Queuing
Condition
MSMQPRESENT
InstallUrl
 
Message
Microsoft Message Queuing features are not installed.  Please add Message Queueing to installed Windows components before installing this package.

That's all there is to it!  Now when the installer first runs, it will look for the msmq_Core value at the MSMQ Setup registry key, and if it doesn't find it, display our error message to the user and bail out.  Now we can be sure our install will fail completely and without taking any action, and the user will be informed how to fix the problem so they can continue with the setup.

We could also have added an InstallUrl, which the installer would display to the user for more information or to download the missing package.

The only problem with this is that the registry values may or may not have changed for the Vista/2k8 operating stack.  I can neither confirm nor deny that; it's possible msmq_Core in 2003 and below is msmq_Server in Vista/2008.  But nothing is ever perfect, is it...

Comments

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant

About The Author

I'm a software developer and musician in Edmonton, AB.  I write mostly web-based software, primarily on the Microsoft stack.  I have an MCPD and several MCTS, but I've only been at this whole developer thing for a few years, and the truth is that I'm still learning more than knowing.  So these are my adventures and experiments and some of it will probably be blatantly wrong...  Just warning ya.