Tridion install path is stored in Windows Registry on the machine where Tridion CM is installed. It might be useful sometimes to read this value programmatically -- e.g. when you need to read some configuration files placed in the Tridion_Home\config folder.
A little issue might occur when you try to read a Registry key in a Windows 32bit vs 64bit, because these values are stored in different Registry locations.
My fellow colleague, Principal Developer Frank van Puffelen (or @puf, for friends :) ), shows a neat way of reading a Registry key irrespective of the code running on a Windows 32 or 64 bit machine:
// Opens a registry either from its normal location or from the Wow6432Node and either from HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.
A little issue might occur when you try to read a Registry key in a Windows 32bit vs 64bit, because these values are stored in different Registry locations.
My fellow colleague, Principal Developer Frank van Puffelen (or @puf, for friends :) ), shows a neat way of reading a Registry key irrespective of the code running on a Windows 32 or 64 bit machine:
// Opens a registry either from its normal location or from the Wow6432Node and either from HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.
private static RegistryKey FindKeyInRegistry(string registryKey)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(registryKey);
if (key == null)
{
key = Registry.CurrentUser.OpenSubKey(
registryKey.Replace(@"Software\", @"Software\Wow6432Node\"));
if (key == null)
{
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key == null)
{
key = Registry.LocalMachine.OpenSubKey(
registryKey.Replace(@"Software\", @"Software\Wow6432Node\"));
}
}
}
return key;
}
Therefore, to read the Tridion_Home directory, you can use the method below:
/// <summary>
/// Gets the Tridion Install Path
/// </summary>
/// <returns></returns>
private String
GetTridionInstallPath()
{
String output = String.Empty;
try
{
RegistryKey RegKey = FindKeyInRegistry(@"Software\Tridion");
output = RegKey.GetValue("InstallDir").ToString();
}
catch (Exception
ex)
{
throw new Exception("Could
not get install path!", ex);
}
return output;
}
Comments