// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Globalization;
using Microsoft.Win32;
namespace ICSharpCode.Core
{
///
/// RegistryService.
///
public static class RegistryService
{
///
/// Gets the registry value.
///
/// Registry hive.
/// Registry key.
/// Registry value.
/// Registry kind.
/// Data.
/// True, if the data was found, False otherwise.
public static bool GetRegistryValue(RegistryHive hive, string key, string value, RegistryValueKind kind, out T data)
{
data = default(T);
try {
using (RegistryKey baseKey = RegistryKey.OpenRemoteBaseKey(hive, String.Empty))
{
if (baseKey != null)
{
using (RegistryKey registryKey = baseKey.OpenSubKey(key, RegistryKeyPermissionCheck.ReadSubTree))
{
if (registryKey != null)
{
RegistryValueKind kindFound = registryKey.GetValueKind(value);
if (kindFound == kind)
{
object regValue = registryKey.GetValue(value, null);
if (regValue != null)
{
data = (T)Convert.ChangeType(regValue, typeof(T), CultureInfo.InvariantCulture);
return true;
}
}
}
}
}
}
return false;
} catch {
return false;
}
}
}
}