none
Registering virtual machine for Hyper-V using WMI and c++ RRS feed

  • Question

  • Hi!

    I have to register new virtual machine from xml file. For this action I need next function:

    ImportVirtualSystemEx()(http://msdn.microsoft.com/en-us/library/dd379583(v=VS.85).aspx). For using this function, I have to call GetVirtualSystemImportSettingData()(http://msdn.microsoft.com/en-us/library/dd379581(v=VS.85).aspx) first because of second parameter to ImportVirtualSystemEx().

    The problem is - I don`t know how to get output parameters from GetVirtualSystemImportSettingData() in c++, and what I have to put into ImportVirtualSystemEx() as a second parameter. How output parameter of GetVirtualSystemImportSettingData() have to be translated into string for ImportVirtualSystemEx()?

    • Moved by Rob Pan Friday, November 11, 2011 2:21 AM (From:Visual C++ General)
    Wednesday, November 9, 2011 6:36 AM

All replies

  • My code:

    	CComPtr<IWbemClassObject> pClass;
        CComPtr<IWbemClassObject> pInParamsDefinition;
    
        //Get class using path
        CHK_HRES(this->m_pWbemServices->GetObject(CComBSTR(L"Msvm_VirtualSystemManagementService"), 0, NULL, &pClass, NULL));
    
        //Get class method
        CHK_HRES(pClass->GetMethod(L"GetVirtualSystemImportSettingData", 0, &pInParamsDefinition, NULL));
    
        //Create class instance
        CHK_HRES(pInParamsDefinition->SpawnInstance(0, &InputParameters));
        
        //setting these parameters
        CHK_HRES(InputParameters->Put(L"ImportDirectory",
                                      0,
                                      &CComVariant(DatastorePath),
                                      0));
        
        //we need instance of the Msvm_VirtualSystemManagementService
        IWbemClassObject* VirtualSystemManagementServiceInstance;
        VirtualSystemManagementServiceInstance=this->GetInstanceByQuery("select * from Msvm_VirtualSystemManagementService");
                           
    					 
    	//Get WMI calss instance
        CComBSTR path(this->GetStrProperty(L"__PATH",&VirtualSystemManagementServiceInstance));
    
        //Call method
        CHK_HRES(m_pWbemServices->ExecMethod(path, 
            CComBSTR(L"GetVirtualSystemImportSettingData"), 
            0, 
            NULL, 
            InputParameters, 
            &OutputParameters, 
            NULL));
                                  
        //Getting ImportSettingData from output parameters
        VARIANT ImportSettingData;                          //ImportSettingData as output parameter
        VariantInit(&ImportSettingData);
        CHK_HRES(OutputParameters->Get(L"ImportSettingData",
    								   0,
    								   &ImportSettingData,
    								   NULL,NULL));
    

    When OutputParameters->Get() Invoked, ImportSettingData stay NULL

    Wednesday, November 9, 2011 11:01 AM
  • Hi,

     

    According to your description, I will move your thread to the correct forum for better support. Thanks for your understanding.

     

    Best Regards,

    Rob


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, November 11, 2011 2:21 AM