Search code examples
c++comwmihyper-v

ConvertToReferencePoint method not working, getting NULL for job parameter (HyperV 2016)


I am trying to create a snapshot first and then convert the snapshot to reference point. Creation of snapshot is successful and I am able to see it in HyperV manager. But when I try to call ConvertToReferencePoint method using Snapshot reference, I am getting NULL for Job output.

After creating snapshot, I am getting the settingsdata associated with it and edit it to rename the snapshot created. I extract the InstanceID field from it and generate the job path which is sent to ConvertToReferencePoint method. CComVariant((L"Msvm_VirtualSystemSettingData.CreationClassName=\"Msvm_VirtualSystemSettingData\",InstanceID=\"" + snapRef + L"\"").c_str()));

Also DeleteSnapshot and DeleteSnapshotTree methods works fine even though they take Msvm_VirtualSystemSettingData path as parameters. Am I missing something.

Similar topic but different problem :(WMI) ExecMethod out parameter - ResultingSnapshot is NULL irrespective of the result of the call, Why?

I even tried hardcoding below parameters using WMI Explorer tool.

AffectedSnapshot=\\hostname\ROOT\virtualization\v2:Msvm_VirtualSystemSettingData.InstanceID="Microsoft:5A58EE16-48E8-46E2-8162-065826537142"
ReferencePointSettings=""

ConvertToReferencePoint: NULL response.

        Wbem::Parameters inParams;
        //inParams.add(L"AffectedSnapshot", CComVariant((L"Msvm_VirtualSystemSettingData.CreationClassName=\"Msvm_VirtualSystemSettingData\",InstanceID=\"" + snapRef + L"\"").c_str()));
        inParams.add(L"AffectedSnapshot", CComVariant(L"\\\\IWF1117030\\ROOT\\virtualization\\v2:Msvm_VirtualSystemSettingData.InstanceID=\"Microsoft:5A58EE16-48E8-46E2-8162-065826537142\""));
        inParams.add(L"ReferencePointSettings", CComVariant(L""));
        Wbem::ParametersPtr outParams(new Wbem::Parameters);
        outParams->add(L"Job", CComVariant());
        m_wbemServices->execObjectMethod(L"Msvm_VirtualSystemSnapshotService", L"Name=\"" + instanceName + L"\"", L"ConvertToReferencePoint", inParams, outParams);

DeleteSnapshot: Works fine.

std::wstring instanceName = getSingleInstanceNameForWMIClass(L"Msvm_VirtualSystemSnapshotService");
        Wbem::Parameters inParams;
        inParams.add(L"AffectedSnapshot", CComVariant((L"Msvm_VirtualSystemSettingData.CreationClassName=\"Msvm_VirtualSystemSettingData\",InstanceID=\"" + snapRef + L"\"").c_str()));
        Wbem::ParametersPtr outParams(new Wbem::Parameters);
        outParams->add(L"Job", CComVariant());
        m_wbemServices->execObjectMethod(L"Msvm_VirtualSystemSnapshotService", L"Name=\"" + instanceName + L"\"", L"DestroySnapshot", inParams, outParams);

There is no error message. Just getting NULL value. If someone has sample code to achieve this please share.


Solution

  • Check how you have created the snapshot in WMI explorer. It should be of type "Recovery" for ConvertToReferencePoint to work.