32-bit registry sandboxing when running under a 64-bit machine

This is a definite gotcha. I was writing a NAnt task that uses the registry to check for the existence of certain installed programs. I hit a problem where when I ran the task directly, it worked fine, but when I ran it through NAnt, it failed.

Turns out this is because I’m using a 64-bit machine, so when running the task via an NUnit test, it was running in 64-bit mode, but when running using the 32-bit NAnt executable, Windows transparently redirects registry accesses to a different node called WOW6432Node (more information here). A lot of registry keys are shared (so I’d written similar NAnt tasks without issue), but some obviously end up being specific to 32-bit or 64-bit applications, and so might be found in the WOW6432Node but not in the normal node, or vice versa. Solution for me was obviously to check which keys existed in both so I could reliably check for a key regardless of which mode the task was running in.