title: CreateSnapshot() does not generate a hyper-v virtual machine snapshot?
body: <pre><code>HRESULT hr;
  IWbemClassObject *pInClass = NULL;
  IWbemClassObject *pOutClass = NULL;
  
  IWbemContext     *pCtx = 0;
  IWbemCallResult  *pResult = 0;
  BSTR snapshotClassPath = SysAllocString(L"Msvm_VirtualSystemSnapshotService");
  hr = m_pWbemServices-&gt;GetObject(
      snapshotClassPath, 
      0, 
      NULL, 
      &amp;m_pWbemClassObject, 
      NULL);
  if (FAILED(hr))
  {
      std::cout &lt;&lt; "Failed to get class object(Msvm_VirtualSystemSnapshotService). Error code = 0x" &lt;&lt; hex &lt;&lt; hr &lt;&lt; std::endl;
      return;
  }
  
  // Create snapshot method
  BSTR MethodNameOne = SysAllocString(L"CreateSnapshot");
  
  hr = m_pWbemClassObject-&gt;GetMethod(
      MethodNameOne,
      0,
      &amp;pInClass,
      &amp;pOutClass
  );
  if (FAILED(hr))
  {
      std::cout &lt;&lt; "Failed to get method(CreateSnapshot). Error code = 0x" &lt;&lt; hex &lt;&lt; hr &lt;&lt; endl;
  }
  cout &lt;&lt; "Succeeded to get method(CreateSnapshot)." &lt;&lt; endl;
  
  
  BSTR virtualSystemSnaphotSettingData = SysAllocString(L"Msvm_VirtualSystemSnapshotSettingData");
  // Get the Msvm_VirtualSystemSnapshotSettingData Class object
  IWbemClassObject * pvirtualSystemSnaphotSettingData = NULL;
  
  hr = m_pWbemServices-&gt;GetObject(
      virtualSystemSnaphotSettingData,
      0,
      pCtx,
      &amp;pvirtualSystemSnaphotSettingData,
      &amp;pResult
  );
  if (FAILED(hr))
  {
      wprintf(L"Error GetObject Msvm_VirtualSystemSnapshotSettingData:0x%08lx\n", hr);
  }
  std::cout &lt;&lt; "Succeeded to get object(Msvm_VirtualSystemSnapshotSettingData)." &lt;&lt; std::endl;
  
  // Create instance of Msvm_VirtualSystemSnapshotSettingData class
  IWbemClassObject * pInpInstOfSnapshotSettingData = NULL;
  hr = pvirtualSystemSnaphotSettingData-&gt;SpawnInstance(
      0,
      &amp;pInpInstOfSnapshotSettingData);
  if (FAILED(hr))
  {
      wprintf(L"Error SpawnInstance Msvm_VirtualSystemSnapshotSettingData:0x%08lx\n", hr);
  }
  std::cout &lt;&lt; "Succeeded to created instance(Msvm_VirtualSystemSnapshotSettingData )." &lt;&lt; std::endl;
  
  // Set the property(Consistency Level)
  BSTR memberOneForVirtualSystemSnapshotSettingData = SysAllocString(L"ConsistencyLevel");
  VARIANT consistencyLevel;
  VariantInit(&amp;consistencyLevel);
  V_VT(&amp;consistencyLevel) = VT_BSTR;
  V_BSTR(&amp;consistencyLevel) = SysAllocString(L"1");
  hr = pInpInstOfSnapshotSettingData-&gt;Put(
      memberOneForVirtualSystemSnapshotSettingData,
      0,
      &amp;consistencyLevel,
      0);
  if (FAILED(hr))
  {
      wprintf(L"Error memberOneForVirtualSystemSnapshotSettingData:0x%08lx\n", hr);
  }
  wprintf(L"Succeeded to set property(ConsistencyLevel), Consistency level:%s\n", consistencyLevel.bstrVal);
  VariantClear(&amp;consistencyLevel);
  </code></pre>
  
  <p>The CreateSnapshot method was called on Windows Hyper-V 2016 and the execution was successful, but the generated virtual machine snapshot was not visible in the Hyper-V GUI.</p>
  
  <p>// Set the property(ElementName)
      BSTR memberThreeForVirtualSystemSnapshotSettingData = SysAllocString(L"ElementName");
      VARIANT elementName;
      VariantInit(&amp;elementName);
      V_VT(&amp;elementName) = VT_BSTR;
      V_BSTR(&amp;elementName) = SysAllocString(vmName);</p>
  
  <pre><code>hr = pInpInstOfSnapshotSettingData-&gt;Put(
      memberThreeForVirtualSystemSnapshotSettingData,
      0,
      &amp;elementName,
      0);
  if (FAILED(hr))
  {
      wprintf(L"Failed to set property(ElementName), Erorr code:0x%08lx\n", hr);
  }
  wprintf(L"Succeeded to set property(ElementName):%s\n", elementName.bstrVal);
  VariantClear(&amp;elementName);
  
  // Set the property(ignore disks that aren't compatible with snapshots)
  BSTR memberTwoForVirtualSystemSnapshotSettingData = SysAllocString(L"IgnoreNonSnapshottableDisks");
  VARIANT ignoreNonSnapshottableDisks;
  ignoreNonSnapshottableDisks.vt = VT_BOOL;
  ignoreNonSnapshottableDisks.boolVal = true;
  
  hr = pInpInstOfSnapshotSettingData-&gt;Put(
      memberTwoForVirtualSystemSnapshotSettingData,
      0,
      &amp;ignoreNonSnapshottableDisks,
      0);
  if (FAILED(hr))
  {
      wprintf(L"Error memberTwoForVirtualSystemSnapshotSettingData:0x%08lx\n", hr);
  }
  wprintf(L"Succeeded to set property(IgnoreNonSnapshottableDisks):%d\n", ignoreNonSnapshottableDisks.boolVal);
  VariantClear(&amp;ignoreNonSnapshottableDisks);
  
  // Create or update instance
  hr = m_pWbemServices-&gt;PutInstance(
      pInpInstOfSnapshotSettingData,
      0,
      pCtx,
      &amp;pResult);
  if (FAILED(hr))
  {
      wprintf(L"Error PutInstance:0x%08lx\n", hr);
  }
  wprintf(L"Succeeded to update the instance.\n");
  
  // Get textual rendering of the object in the MOF syntax
  BSTR objString = NULL;
  hr = pInpInstOfSnapshotSettingData-&gt;GetObjectText(0, &amp;objString);
  if (FAILED(hr))
  {
      wprintf(L"Error GetObjectText:0x%08lx\n", hr);
  }
  wprintf(L"Succeeded to get textual rendering.\n");
  
  BSTR ArgNameTwo = SysAllocString(L"SnapshotSettings");
  VARIANT v;
  V_VT(&amp;v) = VT_BSTR;
  V_BSTR(&amp;v) = objString;
  wprintf(L"Object text: %s\n", objString);
  
  // Pass the second Argument to CreateSnapshot method
  hr = pInClass-&gt;Put(ArgNameTwo, 0, &amp;v, 0);
  if (FAILED(hr))
  {
      wprintf(L"Error ArgNameTwo:0x%08lx\n", hr);
  }
  VariantClear(&amp;v);
  wprintf(L"Succeeded to set property(SnapshotSettings).\n");
  
  // set property(AffectedSystem)
  VARIANT vtProp;
  m_pWbemClassObject-&gt;Get(L"__Path", 0, &amp;vtProp, 0, 0);
  hr = pInClass-&gt;Put(L"AffectedSystem", 0, &amp;vtProp, NULL);
  if (FAILED(hr))
  {
      std::cout &lt;&lt; "Failed to set property(AffectedSystem)." &lt;&lt; std::endl;
  }
  wprintf(L"AffectedSystem: %s\n", vtProp.bstrVal);
  VariantClear(&amp;vtProp);
  
  // Pass the Third Argument to CreateSnapshot method
  BSTR ArgNameThree = SysAllocString(L"SnapshotType");
  VARIANT var;
  VariantInit(&amp;var);
  V_VT(&amp;var) = VT_BSTR;
  V_BSTR(&amp;var) = SysAllocString(L"32768");
  hr = pInClass-&gt;Put(ArgNameThree, 0, &amp;var, 0);
  if (FAILED(hr))
  {
      std::cout &lt;&lt; "Failed to set property(SnapshotType)." &lt;&lt; std::endl;
  }
  wprintf(L"SnapshotType: %s\n", var.bstrVal);
  VariantClear(&amp;var);
  
  // Call the CreateSnapshot method.
  IEnumWbemClassObject* pEnumOb1 = NULL;
  hr = m_pWbemServices-&gt;ExecQuery(
      BSTR(L"WQL"),
      BSTR(L"SELECT * FROM Msvm_VirtualSystemSnapshotService"),
      WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
      NULL,
      &amp;pEnumOb1
  );
  if (FAILED(hr)) {
      std::cout &lt;&lt; "SELECT * FROM Msvm_VirtualSystemSnapshotService, Error code:0x%08lx" &lt;&lt; hex &lt;&lt; hr &lt;&lt; endl;
  }
  std::cout &lt;&lt; "Succeeded to query snapshot." &lt;&lt; std::endl;
  
  IWbemClassObject *pclsObj1 = NULL;
  ULONG uReturn1 = 0;
  
  std::cout &lt;&lt; "Create snapshot..." &lt;&lt; std::endl;
  while (1)
  {
      HRESULT hr = pEnumOb1-&gt;Next(WBEM_INFINITE, 1, &amp;pclsObj1, &amp;uReturn1);
  
      if (FAILED(hr) || !uReturn1)
      {
          break;
      }
      VARIANT vt;
      // Get the value of the path property from Msvm_VirtualSystemSnapshotService Class
      hr = pclsObj1-&gt;Get(L"__Path", 0, &amp;vt, 0, 0);
      if (FAILED(hr))
      {
          std::wcout &lt;&lt; "Failed to get vm's path." &lt;&lt; std::endl;
          break;
      }
      wprintf(L"__PATH:%s \n", vt.bstrVal);
  
      //Call the CreateSnapshot method
      hr = m_pWbemServices-&gt;ExecMethod(
          vt.bstrVal,
          MethodNameOne,
          0,
          NULL,
          pInClass,
          &amp;pOutClass,
          NULL);
      if (FAILED(hr))
      {
          wprintf(L"Failed to execute(CreateSnapshot), Erorr code:0x%08lx\n", hr);
          break;
      }
      wprintf(L"Succeeded to create snapshot.\n");
      Sleep(10);
  
      pclsObj1-&gt;Release();
      pclsObj1 = NULL;
  }
  </code></pre>
  
  <p>The return value of ExecMethod() is 0, that is, the call succeeds, but I did not see the snapshot just created on Hyper-V.</p>