Partager via


How to Post a Configuration Manager Management Point Message

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

To make an asynchronous call to a Microsoft System Center Configuration Manager 2007 endpoint, use ISmsMessaging::Post.

The following C++ example demonstrates how to asynchronously send a discovery data record report to a Configuration Manager 2007 endpoint on a local computer. The example demonstrates the following:

  • Creating the message.

  • Setting the message XML for a data discovery record (DDR) report. The XML consists of header that contains information about the client computer and an attachment that contains the actual data discovery report. In this example, you will need to implement the CreateDDR method that creates the header and report XML. The memory for both must be allocated by using CoTaskMemAlloc. ISmsMessage::SetBodyFromString Method is used to set the message header. ISmsMessage::SetAttachmentFromBuffer Method is used to attach the data discovery report to the message. For a data discovery record report, the attachment must be named {00000000-0000-0000-0000-000000000003}. For information about other Configuration Manager endpoint identifiers, see Configuration Manager Management Point Message Schema.

  • Making the asynchronous call.

  • Cleaning up after the call. In particular, CoTaskMemFree must be called to free the memory that is used by the input message body XML.

Example

HRESULT SendDiscoveryRecord()
{
    ISmsMessaging               *pMessaging = NULL;
    ISmsMessage                 *pMessage = NULL;
    WCHAR                       *pszDDRHeader = NULL;
    WCHAR                       *pszDDRReport = NULL;
    WCHAR                       *pszTrackingID = NULL;
    DWORD                       dwReportLen = 0;

    _BEGIN

        // Create root messaging object.
        _CHECKHR( ::CoCreateInstance(
                        CLSID_SmsMessaging,
                        NULL,
                        CLSCTX_INPROC,
                        IID_ISmsMessaging,
                        (LPVOID*)&pMessaging) );

        // Create message object for the DDR.
        _CHECKHR( pMessaging->CreateMessage(&pMessage) );

        // Set the target of the message to be the DDR endpoint.
        _CHECKHR( pMessage->SetTargetEndpoint(L"MP_DdrEndpoint") );

        // Construct a DDR message. A DDR consists of two pieces, the report
        // header and the report itself.
        _CHECKHR( CreateDDR(&pszDDRHeader, &pszDDRReport) );

        // Compute report length, in bytes. (note null
        // terminator is not included for attachments)
        dwReportLen = lstrlen(pszDDRReport)*sizeof(WCHAR);

        // The report header must be set on the message body, as a string.
        _CHECKHR( pMessage->SetBodyFromString(pszDDRHeader) );

        // The report itself must be set as a message attachment.  The name
        // of the attachment must be a GUID for DDR.
        _CHECKHR( pMessage->SetAttachmentFromBuffer(
                        L"{00000000-0000-0000-0000-000000000003}", // DDR
                        (const BYTE*)pszDDRReport,
                        dwReportLen) );

        // Post the DDR message to the DDR Manager on the local computer.
        _CHECKHR( pMessaging->Post(NULL, pMessage, &pszTrackingID) );

        // Add code to track the message by using the tracking ID.

    _END

    // All cleanup must go after _END block to ensure it gets invoked.

    if(pszTrackingID)
    {
        ::CoTaskMemFree(pszTrackingID);
    }

    if(pszDDRReport)
    {
        ::CoTaskMemFree(pszDDRReport);
    }

    if(pszDDRHeader)
    {
        ::CoTaskMemFree(pszDDRHeader);
    }

    if(pMessage)
    {
        pMessage->Release();
    }

    if(pMessaging)
    {
        pMessaging->Release();
    }

    return _RETVAL;
}

Compiling the Code

Management Point Interfaces DLL.

Security

You can set security options for a message by using ISmsMessage4 Interface. For more information, see Configuration Manager Management Point Interface Security.

See Also

Concepts

About Configuration Manager Management Point Interface Messages
Configuration Manager Management Point Interface
Configuration Manager Management Point Message Schema
ISmsMessage Interface
ISmsMessage2 Interface
ISmsMessage4 Interface
ISmsMessaging Interface