Collapse All
Parallels Virtualization SDK
ContentsIndex
PreviousUpNext
PrlSrv_GetVmList Function
PHT_SERVER  Example

Retrieves a list of virtual machines registered with the specified Parallels Service.

Syntax
PRL_HANDLE PrlSrv_GetVmList(
    PRL_HANDLE hServer
);
File

PrlApiVm.h

Parameters

hServer
A handle of type PHT_SERVER identifying the Parallels Service.

Returns

A handle of type PHT_JOB containing the results of this asynchronous operation or PRL_INVALID_HANDLE if there's not enough memory to instantiate the job object. 

 

Remarks

The information about each virtual machine is returned as a handle of type PHT_VIRTUAL_MACHINE

To get the return code from the PHT_JOB object, use the PrlJob_GetRetCode function. Possible values are: 

PRL_ERR_INVALID_ARG - invalid handle was passed. 

PRL_ERR_SUCCESS - function completed successfully. 

To get the result from the PHT_JOB object:

  1. Use the PrlJob_GetResult function to obtain a handle to the PHT_RESULT object.
  2. Use the PrlResult_GetParamsCount function to get the number of virtual machine in the result set.
  3. Use the PrlResult_GetParamByIndex function in a loop, or by passing a specific index, to obtain a handle to each virtual machine.
Example

The following example illustrates how to obtain a list of virtual machine registered on the specified Parallels Service. The examples assumes that we've already obtain a handle of type PHT_SERVER (the hServer variable) identifying the Parallels Service.

hJob =
PrlSrv_GetVmList( hServer );
PrlJob_Wait( hJob, 10000 );

PrlJob_GetResult( hJob, &hJobResult );
PrlHandle_Free( hJob );

PRL_UINT32 nIndex, nCount;

// Get the number of the virtual machines
// in the list.
PrlResult_GetParamsCount( hJobResult, &nCount );

// Iterate through the list.
for( nIndex = 0; nIndex < nCount ; nIndex++ )
{
    PRL_HANDLE hParam;
    PrlResult_GetParamByIndex( hJobResult, nIndex, &hParam );

    PRL_CHAR sBuf[1024];
    PRL_UINT32 nBufSize = sizeof( sBuf );

    // Get virtual machine name.
    nRetCode =
    PrlVm_GetName( hParam, sBuf, &nBufSize );

    if ( PRL_SUCCEEDED( nRetCode ))
        printf( "VM name: %s.\n", sBuf );
    else
        fprintf( stderr, "PrlFoundVmInfo_GetName failed, error: %s. \n",
            PRL_RESULT_TO_STRING( nRetCode ));

    PrlHandle_Free( hParam );
}
PrlHandle_Free( hJobResult );
Links
© 2021 Parallels International GmbH. All rights reserved.