none
How to associate a .vhd file to a VM using WMI RRS feed

  • Question

  • I have a blank VM and a .vhd file. How can I associate them programmatically?
    From the WMI apis I found that AddVirtualSystemResources Method of the Msvm_VirtualSystemManagementService Class will be helpful. But how should I specify the .vhd file path? I tried to specify it in the second argument but it did not succeed.

    I think an object of Msvm_ResourceAllocationSettingData should be created which holds the .vhd file path when VM and VHD file are associated properly.  But  will the above function create it in itself or do we have to create it?

    thanks,
    Madhu
    Tuesday, May 20, 2008 9:12 AM

Answers


  • Yes, you will use AddVirtualSystemResources Method of the Msvm_VirtualSystemManagementService Class.  For the second argument, you need to pass in a XML string format of the Msvm_ResourceAllocationSettingData instance. 

    Yes, you need to create an object of Msvm_ResourceAllocationSettingData for the second parameter.  You will set the path to your .vhd file in the Connect property.

    Tuesday, May 20, 2008 11:20 PM

All replies


  • Yes, you will use AddVirtualSystemResources Method of the Msvm_VirtualSystemManagementService Class.  For the second argument, you need to pass in a XML string format of the Msvm_ResourceAllocationSettingData instance. 

    Yes, you need to create an object of Msvm_ResourceAllocationSettingData for the second parameter.  You will set the path to your .vhd file in the Connect property.

    Tuesday, May 20, 2008 11:20 PM
  • thanks,

      I'm able to add a VHD file to a VM in powershell now. However I'm not able to do the same in C++. I'm new to WMI, so I suspect there is something wrong in the way I'm using WMI in C++. Perticularly I'm unsure about how to pass a 'string array' when calling a provider method. In this example when I'm calling a addVirtualSystemResources function, I need to pass a string array in its second argument. I created the VARIANT argument as follows.

    VARIANT resourceSettingDataVar;
        resourceSettingDataVar.vt = VT_ARRAY|VT_UI1;
    resourceSettingDataVar.parray = psa; // SAFEARRAY containing the argument.

    The execMethod call gives 4096 as 'returnValue'.

    Is there anything wrong with it?

    thanks,
    Madhu
    Monday, June 2, 2008 9:59 AM