diff --git a/includes/install.core.inc b/includes/install.core.inc
index a74dfdf..88f2a39 100644
--- a/includes/install.core.inc
+++ b/includes/install.core.inc
@@ -1537,6 +1537,9 @@ function _install_module_batch($module, $module_name, &$context) {
 function _install_profile_modules_finished($success, $results, $operations) {
   // Flush all caches to complete the module installation process. Subsequent
   // installation tasks will now have full access to the profile's modules.
+  // Make sure to reset all static caches; especially the one of
+  // system_rebuild_module_data(), so all registries are rebuilt from scratch.
+  drupal_static_reset();
   drupal_flush_all_caches();
 }
 
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 40af458..bb6acaf 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1319,6 +1319,9 @@ class DrupalWebTestCase extends DrupalTestCase {
       $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
     }
 
+    // Rebuild module data so install profile module gets recorded.
+    drupal_static_reset('system_rebuild_module_data');
+    system_rebuild_module_data();
     // Run the profile tasks.
     $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array(
       ':name' => $this->profile,
diff --git a/modules/system/system.module b/modules/system/system.module
index 7d423ab..3db471b 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -2336,6 +2336,7 @@ function _system_rebuild_module_data() {
 
   // Install profile hooks are always executed last.
   $modules[$profile]->weight = 1000;
+  $modules[$profile]->status = 1;
 
   // Set defaults for module info.
   $defaults = array(
diff --git a/modules/system/system.test b/modules/system/system.test
index e0d046e..190c8df 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -2023,6 +2023,8 @@ class SystemInfoAlterTestCase extends DrupalWebTestCase {
  * Tests for the update system functionality.
  */
 class UpdateScriptFunctionalTest extends DrupalWebTestCase {
+  protected $profile = 'testing';
+
   private $update_url;
   private $update_user;
 
@@ -2084,6 +2086,37 @@ class UpdateScriptFunctionalTest extends DrupalWebTestCase {
     $final_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
     $this->assertEqual($original_theme_data, $final_theme_data, t('Visiting update.php does not alter the information about themes stored in the database.'));
   }
+
+  /**
+   * Tests retaining of installation profile information when running update.php.
+   */
+  function testInstallProfile() {
+    // Verify that install profile initially matches expectations.
+    $db_profile = db_query('SELECT * FROM {system} WHERE name = :name', array(
+      ':name' => $this->profile,
+    ))->fetchAssoc();
+    $this->assertEqual($db_profile['name'], $this->profile);
+    // @see _system_rebuild_module_data()
+    $this->assertEqual($db_profile['type'], 'module', 'Install profile is a module.');
+    $this->assertEqual($db_profile['status'], 1, 'Install profile is enabled.');
+    $this->assertEqual($db_profile['weight'], 1000, 'Install profile has a weight of 1000.');
+
+    // Run update.php.
+    $this->drupalLogin($this->update_user);
+    $this->drupalGet($this->update_url, array('external' => TRUE));
+    $this->drupalPost(NULL, array(), t('Continue'));
+    $this->clickLink(t('Front page'));
+
+    // Verify that install profile has not changed.
+    $db_profile = db_query('SELECT * FROM {system} WHERE name = :name', array(
+      ':name' => $this->profile,
+    ))->fetchAssoc();
+    $this->assertEqual($db_profile['name'], $this->profile);
+    // @see _system_rebuild_module_data()
+    $this->assertEqual($db_profile['type'], 'module', 'Install profile is a module.');
+    $this->assertEqual($db_profile['status'], 1, 'Install profile is enabled.');
+    $this->assertEqual($db_profile['weight'], 1000, 'Install profile has a weight of 1000.');
+  }
 }
 
 /**
