Share via


Finding an AD RMS Service

To activate a machine or user, or to acquire a client licensor certificate or sign an issuance license, an appropriate service must be found. Use the DRMGetServiceLocation function for this purpose. The server that hosts the Active Directory Rights Management Services (AD RMS) service can be located in the enterprise or on the Internet.

To find a service by using DRMGetServiceLocation

  1. Use one of the following values in the uServiceLocation parameter to specify where to look for the AD RMS server.

    Value Meaning
    DRM_SERVICE_LOCATION_INTERNET Search on the Internet for an AD RMS server.
    DRM_SERVICE_LOCATION_ENTERPRISE Search in the enterprise.
  2. Use one of the following values in the uServiceType parameter to specify the type of activation.

    Value Meaning
    DRM_SERVICE_TYPE_ACTIVATION Retrieve a computer activation service.
    DRM_SERVICE_TYPE_CERTIFICATION Retrieve a rights account certificate service.
    DRM_SERVICE_TYPE_PUBLISHING Retrieve an issuance license service.
    DRM_SERVICE_TYPE_CLIENTLICENSOR Retrieve a client licensor certificates service for offline publishing.

The following example shows how to use the DRMGetServiceLocation function. The function is called once to determine the length of the string required for the server URL. Memory for the URL is allocated, and the function is called again to copy the URL.

//--------------------------------------------------------------------
// Call DRMGetServiceLocation once to determine whether a service
// location exists and, if so, the size of the buffer needed to
// hold the activation server URL.
// 
hr = DRMGetServiceLocation( 
        hClient,                          // client session handle
        uiServiceType,                    // requested service type
        DRM_SERVICE_LOCATION_ENTERPRISE,  // look in Active Directory
        NULL,                             // issuance license
        &uiStrLen,                        // [in,out] URL length
        NULL                              // [out] service URL
        );

// A service location exists. Reserve memory for the URL.
//
if(SUCCEEDED(hr))
{
  *pwszURL = (PWSTR)HeapAlloc( GetProcessHeap(),
                               HEAP_ZERO_MEMORY,  
                               sizeof( WCHAR ) * ( uiStrLen + 1) );
  if(NULL == *pwszURL)
  {
    wprintf(L"\nMemory allocation failed for activation URL string.\n");
    hr = E_OUTOFMEMORY;
    goto e_Exit;
  }

  // Call DRMGetServiceLocation again to copy the service URL into
  // memory.
  hr = DRMGetServiceLocation( 
          hClient,
          uiServiceType,
          DRM_SERVICE_LOCATION_ENTERPRISE,
          NULL,
          &uiStrLen,
          *pwszURL 
          );

  if(FAILED(hr))
  {
    wprintf(L"\nDRMGetServiceLocation failed. hr = 0x%x\n", hr);
    goto e_Exit;
  }

  wprintf(L"\nDRMGetServiceLocation succeeded.\n");
}

//--------------------------------------------------------------------
// A service location does not exist.
//
else
{
  hr = E_FAIL;
}

e_Exit:

return hr;
}

See Also

Service Discovery
Methods Used by All Client Applications

Send comments about this topic to Microsoft

Build date: 3/13/2008