Click here to Skip to main content
13,259,976 members (48,073 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 23 Mar 2004

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

You may also be interested in...

Comments and Discussions

GeneralAwesome! Pin
BOSSNOSS2-Aug-07 8:28
memberBOSSNOSS2-Aug-07 8:28 
Generalwhere's the exe Pin
fordey427-Jun-07 1:11
memberfordey427-Jun-07 1:11 
QuestionAcknowledge the message Pin
niketha25-Jan-07 13:42
memberniketha25-Jan-07 13:42 
Generalexe Pin
zfd4n13l26-Jul-05 8:44
memberzfd4n13l26-Jul-05 8:44 
GeneralNot working in windows XP Pin
chito29-Sep-04 23:09
memberchito29-Sep-04 23:09 
GeneralRe: Not working in windows XP Pin
Anonymous26-Oct-04 12:39
sussAnonymous26-Oct-04 12:39 
GeneralRe: Not working in windows XP Pin
dbdannydb9-Nov-04 13:13
memberdbdannydb9-Nov-04 13:13 
GeneralRe: Not working in windows XP Pin
Abxi17-Aug-05 15:30
sussAbxi17-Aug-05 15:30 
GeneralRe: Not working in windows XP Pin
VF2-Jun-06 23:15
memberVF2-Jun-06 23:15 
GeneralGreat Job! Pin
Glenn E. Lanier II6-Aug-04 4:57
memberGlenn E. Lanier II6-Aug-04 4:57 
QuestionNot working? Pin
TCavins3-Aug-04 8:17
memberTCavins3-Aug-04 8:17 
I have not been able to get this code to work.

I have compiled it and ran it, a list of the networks servers come up.

I have typed a message and clicked send, but nothing happens.

Any ideas?

Questionhow to receive net send message? Pin
vutrunghieu20-Apr-04 16:29
membervutrunghieu20-Apr-04 16:29 
AnswerRe: how to receive net send message? Pin
Roberto Rivera9-May-04 9:30
sussRoberto Rivera9-May-04 9:30 
Generalmessage spam Pin
No Brayn R4-Apr-04 1:56
memberNo Brayn R4-Apr-04 1:56 
QuestionThanks. Can the user login be included? Pin
bparent24-Mar-04 6:07
memberbparent24-Mar-04 6:07 
AnswerRe: Thanks. Can the user login be included? Pin
GShravanKumar7-Apr-04 19:56
memberGShravanKumar7-Apr-04 19:56 

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

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

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