none
How to use TakeSnapshotVhdSet? RRS feed

  • 问题

  • Hi,everyone!

    I'm trying to use TakeSnapshotVhdSet to create a snapshot,but I don't know what the mean of "A handle to the open virtual disk. This must be a VHD Set file."what's the VHD Set file,how to get the Handle?

    Here is my code:

    int main(void)
    {
    PCWSTR vhdPath = L"D:\\ISO\\testVhd.vhd";
    DWORD opStatus;

    VIRTUAL_STORAGE_TYPE storageType =
    {
    storageType.DeviceId = VIRTUAL_STORAGE_TYPE_DEVICE_UNKNOWN,
    storageType.VendorId = VIRTUAL_STORAGE_TYPE_VENDOR_UNKNOWN
    };

    OPEN_VIRTUAL_DISK_PARAMETERS openParameters;
    openParameters.Version = OPEN_VIRTUAL_DISK_VERSION_1;
    openParameters.Version1.RWDepth = OPEN_VIRTUAL_DISK_RW_DEPTH_DEFAULT;


    TAKE_SNAPSHOT_VHDSET_PARAMETERS takeSnapshotPara;

    memset(&takeSnapshotPara, 0, sizeof(takeSnapshotPara));
    takeSnapshotPara.Version = TAKE_SNAPSHOT_VHDSET_VERSION_1;

    HANDLE vhdHandle;
    ATTACH_VIRTUAL_DISK_PARAMETERS attachParameters =
    {
    attachParameters.Version = ATTACH_VIRTUAL_DISK_VERSION_1,
    };
    do
    {

    if (ERROR_SUCCESS != OpenVirtualDisk(&storageType, vhdPath,
    VIRTUAL_DISK_ACCESS_ALL, OPEN_VIRTUAL_DISK_FLAG_NONE,
    &openParameters, &vhdHandle))
    {
    opStatus = GetLastError();
    break;
    }

    if ((TakeSnapshotVhdSet(vhdHandle, &takeSnapshotPara, TAKE_SNAPSHOT_VHDSET_FLAG_NONE)) != ERROR_SUCCESS)
    {
    opStatus = GetLastError();
    break;
    }

    } while (false);

    CloseHandle(vhdHandle);
    return 0;
    }

    And the TakeSnapshotVhdSet return a Error Code ERROR_NOT_SUPPORTED.

    2016年4月13日 2:12

全部回复

  • Hi,

    Thanks for posting here.

    >>snapshot,but I don't know what the mean of "A handle to the open virtual disk.

    When you open a virtual hard disk or CD or DVD image file for use by suing OpenVirtualDisk function.  If the function succeeds, the handle parameter contains a valid pointer to the new virtual disk object. Inside windows program the handle is very much importance. every process or thread has kernel handle. If you want to access the process or thread. First you should get handle.

    >>how to get the Handle?

    The handle is the above OpenVirtualDisk function’s parameter. If the function succeeds, the handle parameter contains a valid pointer to the new virtual disk object. Than you will get handle. If you have free time please see it https://msdn.microsoft.com/en-us/library/windows/desktop/dd323680(v=vs.85).aspx

    Best Regards,

    Hart

    If your question has been resolved please mark the thread

    2016年4月13日 7:46
    版主
  • Hi,

    I can get the valid handle of VHD or VHDX file handle,and it works on the API AttachVirtualDisk;

    but in

    https://msdn.microsoft.com/en-us/library/windows/desktop/mt414220(v=vs.85).aspx

    it tell me that 

    VirtualDiskHandle [in]
    A handle to the open virtual disk. This must be a VHD Set file.

    But what is "VHD Set file" ,is that means VHD or VHDX file?

    And when i call TakeSnapshotVhdSet,it return ERROR_NOT_SUPPORTED.

    is that the parameters's problem?

    And here is the API TakeSnapshotVhdSet's description

    [Some information relates to pre-released product which may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.]
    Creates a snapshot of the current virtual disk for VHD Set files.


    Is that means this API has not supported?


    2016年4月13日 9:41