diff options
Diffstat (limited to 'src/ext/ComPlus/ca/cppartexec.cpp')
| -rw-r--r-- | src/ext/ComPlus/ca/cppartexec.cpp | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/ext/ComPlus/ca/cppartexec.cpp b/src/ext/ComPlus/ca/cppartexec.cpp index 673bdaf9..06aa16f4 100644 --- a/src/ext/ComPlus/ca/cppartexec.cpp +++ b/src/ext/ComPlus/ca/cppartexec.cpp | |||
| @@ -34,6 +34,7 @@ static HRESULT ReadPartitionAttributes( | |||
| 34 | static void FreePartitionAttributes( | 34 | static void FreePartitionAttributes( |
| 35 | CPI_PARTITION_ATTRIBUTES* pAttrs | 35 | CPI_PARTITION_ATTRIBUTES* pAttrs |
| 36 | ); | 36 | ); |
| 37 | static HRESULT CpiEnsurePartitionsEnabled(); | ||
| 37 | static HRESULT CreatePartition( | 38 | static HRESULT CreatePartition( |
| 38 | CPI_PARTITION_ATTRIBUTES* pAttrs | 39 | CPI_PARTITION_ATTRIBUTES* pAttrs |
| 39 | ); | 40 | ); |
| @@ -71,7 +72,7 @@ HRESULT CpiConfigurePartitions( | |||
| 71 | hr = CpiActionStartMessage(ppwzData, FALSE); | 72 | hr = CpiActionStartMessage(ppwzData, FALSE); |
| 72 | ExitOnFailure(hr, "Failed to send action start message"); | 73 | ExitOnFailure(hr, "Failed to send action start message"); |
| 73 | 74 | ||
| 74 | // ger partition count | 75 | // get partition count |
| 75 | int iCnt = 0; | 76 | int iCnt = 0; |
| 76 | hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); | 77 | hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); |
| 77 | ExitOnFailure(hr, "Failed to read count"); | 78 | ExitOnFailure(hr, "Failed to read count"); |
| @@ -215,7 +216,7 @@ HRESULT CpiConfigurePartitionUsers( | |||
| 215 | hr = CpiActionStartMessage(ppwzData, FALSE); | 216 | hr = CpiActionStartMessage(ppwzData, FALSE); |
| 216 | ExitOnFailure(hr, "Failed to send action start message"); | 217 | ExitOnFailure(hr, "Failed to send action start message"); |
| 217 | 218 | ||
| 218 | // ger partition count | 219 | // get partition count |
| 219 | int iCnt = 0; | 220 | int iCnt = 0; |
| 220 | hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); | 221 | hr = WcaReadIntegerFromCaData(ppwzData, &iCnt); |
| 221 | ExitOnFailure(hr, "Failed to read count"); | 222 | ExitOnFailure(hr, "Failed to read count"); |
| @@ -384,6 +385,69 @@ static void FreePartitionAttributes( | |||
| 384 | CpiFreePropertyList(pAttrs->pPropList); | 385 | CpiFreePropertyList(pAttrs->pPropList); |
| 385 | } | 386 | } |
| 386 | 387 | ||
| 388 | static HRESULT CpiEnsurePartitionsEnabled() | ||
| 389 | { | ||
| 390 | HRESULT hr = S_OK; | ||
| 391 | |||
| 392 | ICatalogCollection* piLocalComputerColl = NULL; | ||
| 393 | IDispatch* piDisp = NULL; | ||
| 394 | ICatalogObject* piLocalComputerObj = NULL; | ||
| 395 | VARIANT vtVal; | ||
| 396 | BSTR bsPartitionsEnabledName = ::SysAllocString(L"PartitionsEnabled"); | ||
| 397 | long numChanges = 0; | ||
| 398 | |||
| 399 | ::VariantInit(&vtVal); | ||
| 400 | |||
| 401 | // get collection | ||
| 402 | hr = CpiExecGetCatalogCollection(L"LocalComputer", &piLocalComputerColl); | ||
| 403 | ExitOnFailure(hr, "Failed to get catalog collection"); | ||
| 404 | |||
| 405 | // find object, there will be only one in the LocalComputer collection | ||
| 406 | hr = piLocalComputerColl->get_Item(0, &piDisp); | ||
| 407 | ExitOnFailure(hr, "Failed to get object from collection"); | ||
| 408 | |||
| 409 | hr = piDisp->QueryInterface(IID_ICatalogObject, (void**)&piLocalComputerObj); | ||
| 410 | ExitOnFailure(hr, "Failed to get IID_ICatalogObject interface"); | ||
| 411 | |||
| 412 | // and then we get the value of the PartitionsEnabled property | ||
| 413 | hr = piLocalComputerObj->get_Value(bsPartitionsEnabledName, &vtVal); | ||
| 414 | if (!vtVal.boolVal) | ||
| 415 | { | ||
| 416 | vtVal.boolVal = true; | ||
| 417 | hr = piLocalComputerObj->put_Value(bsPartitionsEnabledName, vtVal); | ||
| 418 | ExitOnFailure(hr, "Failed to put value to Enable COM+ PartitionsEnabled property"); | ||
| 419 | hr = piLocalComputerColl->SaveChanges(&numChanges); | ||
| 420 | ExitOnFailure(hr, "Failed to save PartitionsEnabled property"); | ||
| 421 | |||
| 422 | // we'll read back the hopefully updated values of the PartitionsEnabled property | ||
| 423 | // if it's still False, then we're on a Windows Desktop that doesn't allow Partitions | ||
| 424 | // (as of Windows Server2003 Microsoft limited Partitions to only ServerOS platforms) | ||
| 425 | hr = piLocalComputerObj->get_Value(bsPartitionsEnabledName, &vtVal); | ||
| 426 | ExitOnFailure(hr, "Failed to read PartitionsEnabled property"); | ||
| 427 | } | ||
| 428 | |||
| 429 | if (vtVal.boolVal) | ||
| 430 | { | ||
| 431 | // everything went well, we have the Partitioning available | ||
| 432 | hr = S_OK; | ||
| 433 | } | ||
| 434 | else | ||
| 435 | { | ||
| 436 | // we're on a Desktop OS, or couldn't otherwise enable partitioning | ||
| 437 | WcaLog(LOGMSG_STANDARD, "Failed to Enable COM+ PartitionEnabled property. This suggests Partitioning was attempted on a Desktop OS, which is not supported"); | ||
| 438 | hr = S_FALSE; | ||
| 439 | } | ||
| 440 | |||
| 441 | LExit: | ||
| 442 | // clean up | ||
| 443 | ReleaseObject(piLocalComputerColl); | ||
| 444 | ReleaseObject(piLocalComputerObj); | ||
| 445 | ReleaseBSTR(bsPartitionsEnabledName); | ||
| 446 | ::VariantClear(&vtVal); | ||
| 447 | |||
| 448 | return hr; | ||
| 449 | } | ||
| 450 | |||
| 387 | static HRESULT CreatePartition( | 451 | static HRESULT CreatePartition( |
| 388 | CPI_PARTITION_ATTRIBUTES* pAttrs | 452 | CPI_PARTITION_ATTRIBUTES* pAttrs |
| 389 | ) | 453 | ) |
| @@ -408,6 +472,9 @@ static HRESULT CreatePartition( | |||
| 408 | 472 | ||
| 409 | if (S_FALSE == hr) | 473 | if (S_FALSE == hr) |
| 410 | { | 474 | { |
| 475 | hr = CpiEnsurePartitionsEnabled(); | ||
| 476 | ExitOnFailure(hr, "Failed to enable partitions"); | ||
| 477 | |||
| 411 | // create partition | 478 | // create partition |
| 412 | hr = CpiAddCollectionObject(piPartColl, &piPartObj); | 479 | hr = CpiAddCollectionObject(piPartColl, &piPartObj); |
| 413 | ExitOnFailure(hr, "Failed to add partition to collection"); | 480 | ExitOnFailure(hr, "Failed to add partition to collection"); |
