0

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?

4
  • How do you call this method? Which hive? Commented May 13, 2015 at 7:17
  • What if another versions of PostgreSQL is installed ? Commented May 13, 2015 at 8:46
  • @ Vivek , postgresql-x64-9.4 ,is already installed in my machine Commented May 13, 2015 at 8:48
  • try this way, its a good one Commented May 13, 2015 at 9:04

1 Answer 1

1

Check Registry Entry using C#

var postgres = Registry.CurrentUser.OpenSubKey(@"Software\pgadmin");
if(postgres != null)
{
    //postgreSQL is installed on your machine
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.