2016-12-05 92 views
0
  1. 我在winserver 2012r2上創建hyper-v快照後無法獲得結果,這意味着我不知道創建的快照的instanceID。如何在wmi中創建hyper-v快照後得到結果

  2. 我已經看到了類Msvm_VirtualSytemSnapshotService的方法CreateSnapshot,其輸入PARAMS包括ResultingSnapshot引用CIM_VirtualSystemSettingData,其輸出PARAMS包括ResultingSnapshot了。

  3. 我創建了一個CIM_VirtualSystemSettingData實例來調用方法CreateSnapshot。當我運行程序,它告訴我

無效的方法參數(S)

如果我調用方法CreateSnapshot沒有ResultingSnapshot,我創造佳績。

請給我一些建議!

代碼:

ManagementObject virtualSystemService = Utility.GetServiceObject(scope,"Msvm_VirtualSystemSnapshotService"); 

    ManagementBaseObject inParams = virtualSystemService.GetMethodParameters("CreateSnapshot"); 

    ManagementPath resultingSettingDataPath = new ManagementPath("CIM_VirtualSystemSettingData"); 
    ManagementClass serviceClass = new ManagementClass(scope, resultingSettingDataPath, null); 
    ManagementObject resultingSettingData = serviceClass.CreateInstance(); 

    ManagementObject vm = Utility.GetTargetComputer(vmName, scope); 

    inParams.SetPropertyValue("AffectedSystem", vm.Path.Path); 

    inParams.SetPropertyValue("SnapshotType", snapshotType); 

    inParams.SetPropertyValue("ResultingSnapshot", serviceClass.createInstance()); 

    //inParams.SetPropertyValue("SnapshotSettings", null); 
    // inParams.SetPropertyValue("Job", null); 
    ManagementBaseObject outParams = virtualSystemService.InvokeMethod("CreateSnapshot", inParams, null);` 

回答

0

你應該從outParams作業對象和ResultingSnapshot對象,而不是將其作爲輸入參數, 調用CreateSnapshot方法得到這份工作對象,並檢查其狀態後,如果Job完成了,那麼你可以從outParams中獲得ResultingSnapshot對象。

bool snapShotCreated = false; 
if ((UInt32)outParams["ReturnValue"] == 4096) // Job in progress 
{ 
    // Get the job object to continue querying 
    string jobPath = outParams["job"].ToString(); 
    ManagementObject job = new ManagementObject(jobPath); 

    // TODO: You now have the job object, query it until the job completed. 

} 
else if ((UInt32)outParams["ReturnValue"] == 0) 
{ 
    // job completed 
    snapShotCreated = true; 
} 
else 
{ 
    // Error 
} 

if (snapShotCreated) 
{ 
    string resultingSystemPath = outParams["ResultingSnapshot"].ToString(); 
    ManagementObject resultingSystem = new ManagementObject(resultingSystemPath); 
} 

讓我知道,如果它的工作...

相關問題