NetMessageBufferSend (netapi32)
Last changed: -84.161.130.31

.
Summary
TODO - a short description

C# Signature:

[DllImport("netapi32.dll")]
static extern int NetMessageBufferSend(
    [MarshalAs(UnmanagedType.LPWStr)] string servername,
    [MarshalAs(UnmanagedType.LPWStr)] string msgname,
    [MarshalAs(UnmanagedType.LPWStr)] string fromname,
    [MarshalAs(UnmanagedType.LPWStr)] string buf,
    int buflen);

VB Signature:

Declare Function NetMessageBufferSend Lib "netapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

The Alerter service must be running for NetMessageBufferSend to function.

Sample Code:

C# Example code

This is a simple console program which lets you send messages (quite similar to the NET SEND command...).

Usage
sendnetmsg.exe srcName dstName message

For example you can use the name of your machine as srcName and dstName and the message will be sent to yourself

using System;
using System.Runtime.InteropServices;

public class SendNetMsg
{
    const int NERR_Success         = 0;
    const int NERR_BASE        = 2100;
    const int NERR_NameNotFound    = (NERR_BASE+173); // The message alias could not be found on the network.
    const int NERR_NetworkError    = (NERR_BASE+36);  // A general network error occurred.
    const int ERROR_ACCESS_DENIED      = 5;
    const int ERROR_INVALID_PARAMETER  = 87;
    const int ERROR_NOT_SUPPORTED      = 50;

    [DllImport("netapi32.dll")]
    public static extern int NetMessageBufferSend(
        [MarshalAs(UnmanagedType.LPWStr)] string servername,
        [MarshalAs(UnmanagedType.LPWStr)] string msgname,
        [MarshalAs(UnmanagedType.LPWStr)] string fromname,
        [MarshalAs(UnmanagedType.LPWStr)] string buf,
        int buflen);

    public static void Main (String[] argv)
    {
        if (argv.Length < 3)
        {
        Console.WriteLine ("sendnetmsg.exe srcName dstName msg");
        return;
        }

        int retVal = NetMessageBufferSend (null, argv[1], argv[0], argv[2], argv[2].Length * 2);    

        if (retVal == NERR_NameNotFound)
        Console.WriteLine ("Error: NERR_NameNotFound") ;
        else if (retVal == NERR_NetworkError)
        Console.WriteLine ("Error: NERR_NetworkError") ;
        else if (retVal == ERROR_ACCESS_DENIED)
        Console.WriteLine ("Error: ERROR_ACCESS_DENIED") ;
        else if (retVal == ERROR_INVALID_PARAMETER)
        Console.WriteLine ("Error: ERROR_INVALID_PARAMETER") ;
        else if (retVal == ERROR_NOT_SUPPORTED)
        Console.WriteLine ("Error: ERROR_NOT_SUPPORTED") ;
        else if (retVal != 0)
        Console.WriteLine ("Unknown error returned.\nError code {0}", retVal) ;
    }
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation