共用方式為


Msvm_ImageManagementService 類別的 MergeVirtualHardDisk 方法

將差異鏈結中的子虛擬硬碟與鏈結中的一或多個父虛擬硬碟合併。 如需此方法的使用限制,請參閱。

如果執行此函式的使用者沒有更新虛擬機器的許可權,則此函式將會失敗。

語法

uint32 MergeVirtualHardDisk(
  [in]  string              SourcePath,
  [in]  string              DestinationPath,
  [out] CIM_ConcreteJob REF Job
);

參數

SourcePath [in]

類型: 字串

完整路徑,指定要合併之虛擬硬碟檔案的位置。

DestinationPath [in]

類型: 字串

完整路徑,指定要合併資料之父虛擬硬碟檔案的位置。 這可能是合併檔案的立即父虛擬硬碟,或父磁片映射在差異鏈結的幾個層級上。

作業 [out]

類型: CIM_ConcreteJob

如果作業是以非同步方式執行,這個方法會傳回 4096,而此參數將包含衍生自 CIM_ConcreteJob之物件的參考。

傳回值

類型: uint32

這個方法可以傳回下列其中一個值。

已完成,沒有錯誤 (0)

已檢查方法參數 - 作業啟動 (4096)

失敗 (32768)

拒絕存取 (32769)

不支援 (32770)

狀態未知 , (32771)

時 (32772)

不正確參數 (32773)

系統正在使用 中 (32774)

此作業的狀態無效 , (32775)

不正確的資料類型 (32776)

( 32777) 無法使用系統

記憶體不足 (32778)

找不到 檔案 (32779)

備註

子虛擬硬碟必須離線。

只有下列類型的虛擬硬碟可以搭配此方法使用:

  • 差異 VHD
  • 差異 VHDX

Msvm_ImageManagementService類別的存取可能會受限於 UAC 篩選。 如需詳細資訊,請參閱 使用者帳戶控制和 WMI

範例

下列 C# 範例會展開虛擬硬碟檔案。 您可以在虛擬 範例的常見公用程式中找到參考的公用程式, (V2)

// Merges a VHD into a parent VHD.
// ChildPath: The path to the VHD to merge.</param>
// ParentPath: The path to the parent into which to merge.</param>
public static void MergeVirtualHardDisk(string ChildPath, string ParentPath)
{
    ManagementScope scope = new ManagementScope(@"root\virtualization\v2", null);
    ManagementObject imageService = Utility.GetServiceObject(scope, "Msvm_ImageManagementService");

    ManagementBaseObject inParams = imageService.GetMethodParameters("MergeVirtualHardDisk");

    inParams["SourcePath"] = ChildPath;
    inParams["DestinationPath"] = ParentPath;

    ManagementBaseObject outParams = imageService.InvokeMethod("MergeVirtualHardDisk", inParams, null);

    if ((UInt32)outParams["ReturnValue"] == ReturnCode.Started)
    {
        if (Utility.JobCompleted(outParams, scope))
        {
            Console.WriteLine("MergeVirtualHardDisk succeeded.");
        }
        else
        {
            Console.WriteLine("MergeVirtualHardDisk failed.");
        }
    }

    outParams.Dispose();
    inParams.Dispose();
    imageService.Dispose();
}

規格需求

需求
最低支援的用戶端
Windows 8 [僅限傳統型應用程式]
最低支援的伺服器
Windows Server 2012 [僅限傳統型應用程式]
命名空間
Root\Virtualization\V2
MOF
WindowsVirtualization.V2.mof
DLL
Vmms.exe

另請參閱

CIM_ConcreteJob

Msvm_ImageManagementService