Click here to Skip to main content
Click here to Skip to main content

Batch Net Send

, 23 Mar 2004
Rate this:
Please Sign up or sign in to vote.
Send network messages to several recipients


This article shows how to send multiple network messages using Platform Invoke and the Windows Network functions.


A few weeks ago I felt the need to send several network messages. After some time sending them through the Windows command prompt I thought that there should be a easier way. So I stumbled on the internet with some multiple network send GUIs which did the trick for the moment. But this made me curious, what was the code behind those GUIs like? So I made a search here in CodeProject and found a similar article from a fellow contributor which provided a front-end for net send. But after looking at the source code, I realized that the only thing it did was to generate a .bat file with the net send commands and messages, and execute it on the shell. I tryed to replicate the idea but without using the .bat file, so I discovered a windows function that did exactly what I wanted. The NetMessageBufferSend function.

Using the code

In order to invoke the windows function, Platform Invoke was used. This enabled me to use C# as the development language instead of having to use MFC or Win32 API. This code basically invokes two main functions. NetMessageBufferSend to send the message and NetServerEnum to extract the list of available computers in the network.

//  Invoking  the  NetServerEnum  function
int  ret  =  NetServerEnum(null,101,out  buf,-1,
    ref  entriesread,ref  totalentries,

SERVER_INFO_101  server  =  (SERVER_INFO_101)
  Marshal.PtrToStructure(new  IntPtr(ptr),typeof(SERVER_INFO_101));

The NetServerEnum function returns different types of structures according to the second parameter passed. In this case we want the information contained in a SERVER_INFO_101 structure, so parameter '101' is passed. entriesread and totalentries variables store the number of entries returned by this function call and the total number of available servers of that type in the network respectively. SV_TYPE_WORKSTATION tells the function the type of servers we want to list. After choosing which workstation we want the message to be sent to, its time to call the NetMessageBufferSend function.

//  Invoking  the  NetMessageBufferSend  function
int  nRet  =  NetMessageBufferSend(null,  
  treeView1.Nodes[i].Text,  from,  textBox1.Text,  
  textBox1.Text.Length  *  2  +  2);


  • 22/03/2004 Initial Version


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Francisco Prata
Web Developer
Portugal Portugal
No Biography provided

Comments and Discussions

GeneralAwesome! PinmemberBOSSNOSS2-Aug-07 8:28 
Generalwhere's the exe Pinmemberfordey427-Jun-07 1:11 
QuestionAcknowledge the message Pinmemberniketha25-Jan-07 13:42 
Generalexe Pinmemberzfd4n13l26-Jul-05 8:44 
GeneralNot working in windows XP Pinmemberchito29-Sep-04 23:09 
GeneralRe: Not working in windows XP PinsussAnonymous26-Oct-04 12:39 
GeneralRe: Not working in windows XP Pinmemberdbdannydb9-Nov-04 13:13 
GeneralRe: Not working in windows XP PinsussAbxi17-Aug-05 15:30 
GeneralRe: Not working in windows XP PinmemberVF2-Jun-06 23:15 
Or you may use some tcp/ip replacement instead:
GeneralGreat Job! PinmemberGlenn E. Lanier II6-Aug-04 4:57 
QuestionNot working? PinmemberTCavins3-Aug-04 8:17 
Questionhow to receive net send message? Pinmembervutrunghieu20-Apr-04 16:29 
AnswerRe: how to receive net send message? PinsussRoberto Rivera9-May-04 9:30 
Generalmessage spam PinmemberNo Brayn R4-Apr-04 1:56 
QuestionThanks. Can the user login be included? Pinmemberbparent24-Mar-04 6:07 
AnswerRe: Thanks. Can the user login be included? PinmemberGShravanKumar7-Apr-04 19:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 24 Mar 2004
Article Copyright 2004 by Francisco Prata
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid