I used to use the following code to get an installation directory for
a file. The problem arises when the key is on a 64bit machine it is no
longer in CLSID\\guid\\InProcServer32" but in \Wow6432Node\CLSID\guid
\InprocServer32.
Is there a better windows api call that I can make so I don't have to
make this check twice?
public static string GetInstallationDirectory()
{
string directory = string.Empty;
try
{
RegistryKey key = Registry.ClassesRoot.OpenSubKey("somekey");
if (key != null)
{
string className = Convert.ToString(key.GetValue(string.Empty));
if (!string.IsNullOrEmpty(className))
{
key =
Registry.ClassesRoot.OpenSubKey(string.Format("CLSID\\{0}\
\InProcServer32", className));
if (key != null)
{
string path =
Convert.ToString(key.GetValue(string.Empty));
if (!string.IsNullOrEmpty(path))
directory = Path.GetDirectoryName(path);
}
}
if (key != null)
key.Close();
}
}
catch (System.Security.SecurityException ex)
{
}
return directory;
}