【发布时间】:2015-05-13 06:43:43
【问题描述】:
我有一个带有 PostgreSQL 的 WPF 应用程序,我需要检查 PostgreSQL 是否安装在本地计算机上。
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;
}
但即使我安装了它,我总是得到错误的结果(= 未安装)。我在这里错过了什么?
【问题讨论】:
-
这个方法怎么称呼?哪个蜂巢?
-
如果安装了其他版本的PostgreSQL怎么办?
-
@Vivek,postgresql-x64-9.4,已经安装在我的机器上
-
试试this的方式,不错
标签: c# wpf postgresql installation