I have a WPF application with PostgreSQL, I need to check PostgreSQL is installed in the local machine.
const string PostgresSQLKeyName = "SOFTWARE\\PostgreSQL\\Installations\\postgresql-x64-9.4";
const string NetRegKeyValue = "DllFullPath";
private static bool GetRegistryValue<T>(RegistryHive hive, string key, string value, RegistryValueKind kind, out T data)
{
bool success = false;
data = default(T);
using (RegistryKey baseKey = RegistryKey.OpenRemoteBaseKey(hive, String.Empty)) {
if (baseKey != null) {
using (RegistryKey registryKey = baseKey.OpenSubKey(key, RegistryKeyPermissionCheck.ReadSubTree)) {
if (registryKey != null) {
try {
// If the key was opened, try to retrieve the value.
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);
success = true;
}
}
}
catch (IOException ex) {
//Logger.Write(ex, "GetRegistryValue-Detection.cs", "GetRegistryValue");
success = false;
}
}
}
}
}
return success;
}
But I am always getting the result false (= not installed) even if I installed it. What am I missing here?