aboutsummaryrefslogtreecommitdiff
path: root/src/engine/registration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/registration.cpp')
-rw-r--r--src/engine/registration.cpp63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/engine/registration.cpp b/src/engine/registration.cpp
index dc4b88bf..fc5ae627 100644
--- a/src/engine/registration.cpp
+++ b/src/engine/registration.cpp
@@ -92,6 +92,10 @@ static HRESULT UpdateBundleNameRegistration(
92 __in BURN_VARIABLES* pVariables, 92 __in BURN_VARIABLES* pVariables,
93 __in HKEY hkRegistration 93 __in HKEY hkRegistration
94 ); 94 );
95static BOOL IsWuRebootPending();
96static BOOL IsBundleRebootPending(
97 __in BURN_REGISTRATION* pRegistration
98);
95 99
96// function definitions 100// function definitions
97 101
@@ -443,7 +447,10 @@ extern "C" HRESULT RegistrationSetVariables(
443 ExitOnFailure(hr, "Failed to overwrite the bundle tag built-in variable."); 447 ExitOnFailure(hr, "Failed to overwrite the bundle tag built-in variable.");
444 448
445 hr = VariableSetVersion(pVariables, BURN_BUNDLE_VERSION, pRegistration->pVersion, TRUE); 449 hr = VariableSetVersion(pVariables, BURN_BUNDLE_VERSION, pRegistration->pVersion, TRUE);
446 ExitOnFailure(hr, "Failed to overwrite the bundle tag built-in variable."); 450 ExitOnFailure(hr, "Failed to overwrite the bundle version built-in variable.");
451
452 hr = VariableSetNumeric(pVariables, BURN_REBOOT_PENDING, IsBundleRebootPending(pRegistration) || IsWuRebootPending(), TRUE);
453 ExitOnFailure(hr, "Failed to overwrite the bundle reboot-pending built-in variable.");
447 454
448LExit: 455LExit:
449 ReleaseStr(sczBundleManufacturer); 456 ReleaseStr(sczBundleManufacturer);
@@ -491,17 +498,10 @@ extern "C" HRESULT RegistrationDetectResumeType(
491 ) 498 )
492{ 499{
493 HRESULT hr = S_OK; 500 HRESULT hr = S_OK;
494 LPWSTR sczRebootRequiredKey = NULL;
495 HKEY hkRebootRequired = NULL;
496 HKEY hkRegistration = NULL; 501 HKEY hkRegistration = NULL;
497 DWORD dwResume = 0; 502 DWORD dwResume = 0;
498 503
499 // Check to see if a restart is pending for this bundle. 504 if (IsBundleRebootPending(pRegistration))
500 hr = StrAllocFormatted(&sczRebootRequiredKey, REGISTRY_REBOOT_PENDING_FORMAT, pRegistration->sczRegistrationKey);
501 ExitOnFailure(hr, "Failed to format pending restart registry key to read.");
502
503 hr = RegOpen(pRegistration->hkRoot, sczRebootRequiredKey, KEY_QUERY_VALUE, &hkRebootRequired);
504 if (SUCCEEDED(hr))
505 { 505 {
506 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_REBOOT_PENDING; 506 *pResumeType = BOOTSTRAPPER_RESUME_TYPE_REBOOT_PENDING;
507 ExitFunction1(hr = S_OK); 507 ExitFunction1(hr = S_OK);
@@ -554,8 +554,6 @@ extern "C" HRESULT RegistrationDetectResumeType(
554 554
555LExit: 555LExit:
556 ReleaseRegKey(hkRegistration); 556 ReleaseRegKey(hkRegistration);
557 ReleaseRegKey(hkRebootRequired);
558 ReleaseStr(sczRebootRequiredKey);
559 557
560 return hr; 558 return hr;
561} 559}
@@ -1591,3 +1589,46 @@ LExit:
1591 1589
1592 return hr; 1590 return hr;
1593} 1591}
1592
1593static BOOL IsWuRebootPending()
1594{
1595 HRESULT hr = S_OK;
1596 BOOL fRebootPending = FALSE;
1597
1598 // Do a best effort to ask WU if a reboot is required. If anything goes
1599 // wrong then let's pretend a reboot is not required.
1600 hr = ::CoInitialize(NULL);
1601 if (SUCCEEDED(hr) || RPC_E_CHANGED_MODE == hr)
1602 {
1603 hr = WuaRestartRequired(&fRebootPending);
1604 if (FAILED(hr))
1605 {
1606 fRebootPending = FALSE;
1607 }
1608
1609 ::CoUninitialize();
1610 }
1611
1612 return fRebootPending;
1613}
1614
1615static BOOL IsBundleRebootPending(BURN_REGISTRATION* pRegistration)
1616{
1617 HRESULT hr = S_OK;
1618 LPWSTR sczRebootRequiredKey = NULL;
1619 HKEY hkRebootRequired = NULL;
1620 BOOL fBundleRebootPending = FALSE;
1621
1622 // Check to see if a restart is pending for this bundle.
1623 hr = StrAllocFormatted(&sczRebootRequiredKey, REGISTRY_REBOOT_PENDING_FORMAT, pRegistration->sczRegistrationKey);
1624 ExitOnFailure(hr, "Failed to format pending restart registry key to read.");
1625
1626 hr = RegOpen(pRegistration->hkRoot, sczRebootRequiredKey, KEY_QUERY_VALUE, &hkRebootRequired);
1627 fBundleRebootPending = SUCCEEDED(hr);
1628
1629LExit:
1630 ReleaseStr(sczRebootRequiredKey);
1631 ReleaseRegKey(hkRebootRequired);
1632
1633 return fBundleRebootPending;
1634}