Broadcasting a Message

Need to send a message to another NT user? Why not use the Net Send command?

If you're using NT 4.0 in your office, trying clicking 'Start', 'Run', then typing in: Net Send - then clicking OK.

In place of , type in a colleagues username or machine name. In place of , insert your own witty one-liner.

When you click OK, NT will broadcast your message - and the specified user should have it popup on his/her screen.

Now, it's a little-known fact, but you can actually access this message sending functionality through the API. And we have all the code you need right here, ready for you to copy-and-paste, allowing you to instantly creating your own mini messenger or office news broadcast system!

To use, call BroadcastMessage, passing in three arguments - a user or machine name, a sender name, plus your actual message. The function will return a True or False dependant on success.

Sample Usage

x = BroadcastMessage("PYTHON", "Karl", "Boooo! It's me. Time for tea?")

Code

Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" _
(yServer As Any, yToName As Byte, yFromName As Any, yMsg As Byte, _
ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&

Public Function BroadcastMessage(UserOrMachine As String, _
FromName As String, Message As String) As Boolean
   
    Dim ToName() As Byte
    Dim FromName() As Byte
    Dim MessageToSend() As Byte
    
    'Put data into byte arrays
    ToName = UserOrMachine & vbNullChar
    FromName = FromName & vbNullChar
    MessageToSend = Message & vbNullChar
    
    'Broadcast message via API
    If NetMessageBufferSend(ByVal 0&, ToName(0), ByVal 0&, _
    FromName(0), UBound(MessageToSend)) = NERR_Success Then
        'Return True if it worked
        BroadcastMessage = True
    End If

End Function


Beaded Necklace | Banner Ad Network | Video | Shades | Discount Window Shades