(WMI) CreateSnapshot() not working with SnapshotType 32768

Mayank Srivastava 41 Reputation points
2020-11-12T07:22:18.783+00:00

Hi,

I am actually trying to create a Reference Point for my Hyper-V VM for RCT based backup. I am trying to do this by C#.

For ConvertToReferencePoint() to work my Snapshot Type should be recovery.

Which I found out from here: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/createsnapshot-msvm-virtualsystemsnapshotservice

For recovery snapshot, we use snapshot type 32768 for CreateSnapshot().

Which I found out from here: https://social.technet.microsoft.com/Forums/ie/en-US/39d8b7f7-8efa-48e5-8750-869d2ca8bf70/what-is-the-hyperv-recovery-snapshot-type?forum=winserverhyperv#:~:text=The%20recovery%20snapshot%20sounds%20like,same%20as%20a%20VM%20checkpoint.

But when I use 32768 in my Snapshot Setting. It gives error.
Log: Checkpoint creation failed for 'Ubuntu1' because an invalid checkpoint type has been specified. (Virtual machine ID 5C773BB5-B630-48B4-AB9E-71C548F3FAE4)

This is what i have so far:

//CreateSnapShot() settings

inParams["AffectedSystem"] = vm.Path.Path;
ManagementObject snapshotSettings = GetObject("Msvm_VirtualSystemSnapshotSettingData",scope);
snapshotSettings["ConsistencyLevel"] = 1;
snapshotSettings["IgnoreNonSnapshottableDisks"] = true;
snapshotSettings["GuestBackupType"] = 1;
inParams["SnapshotSettings"] = snapshotSettings.ToString();
inParams["SnapshotType"] = 32768;

//Invoke Method:

ManagementBaseObject outParams = virtualSystemService.InvokeMethod("CreateSnapshot", inParams, null);

CreateSnapshot() Link: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/createsnapshot-msvm-virtualsystemsnapshotservice

Am I missing something?

Thanks,
Mayank Srivastava

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,427 questions
{count} votes

Accepted answer
  1. Drake Wu - MSFT 991 Reputation points
    2020-11-17T03:47:26.21+00:00

    Hi @Mayank Srivastava , I can reproduce this issue and get error code 32773 which usually means "Invalid parameter".

    After comparing the PS code with your code, I found that the problem occurs in the SnapshotSettings parameter instead of SnapshotType. The following code will return different values:

    string str1 = snapshotSettings.GetText(TextFormat.WmiDtd20);  
    string str2 = snapshotSettings.ToString();  
    

    result: str1 = "somevalue in WmiDtd20 format" and str2 =""//null. So you should use the version of str1 to set the SnapshotSettings parameter and it works for me.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful