public static string ReadRegKey(RegistryHive hive, string keyPath, string valueName) { if (!Is32BitProcessOn64BitProcessor()) { return Registry.GetValue(Path.Combine(hive.GetNameX(), keyPath), valueName, null) as string; } UIntPtr hKey = UIntPtr.Zero; int openKeyErrorCode = 0; try { UIntPtr rootKeyPtr = hive.AsUIntPtrX(); openKeyErrorCode = RegOpenKeyEx(rootKeyPtr, keyPath, 0, (int) (KeyAccess.KEY_READ | KeyAccess.KEY_WOW64_64KEY), out hKey); if (openKeyErrorCode != 0) { return null; } uint size = 1024; uint type; var keyBuffer = new StringBuilder((int)size); try { int regQueryValueErrorCode = RegQueryValueEx(hKey, valueName, 0, out type, keyBuffer, ref size); return regQueryValueErrorCode != 0 ? null : keyBuffer.ToString(); } catch (Exception e) { return null; } } finally { if (openKeyErrorCode == 0) { RegCloseKey(hKey); } } }