Click here to Skip to main content
Click here to Skip to main content
Go to top

Batch Net Send

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

Introduction

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

Background

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,
    SV_101_TYPES.SV_TYPE_WORKSTATION,null,0);

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);

History

  • 22/03/2004 Initial Version

License

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

Share

About the Author

Francisco Prata
Web Developer
Portugal Portugal
No Biography provided

Comments and Discussions

 
GeneralAwesome! PinmemberBOSSNOSS2-Aug-07 7:28 
Generalwhere's the exe Pinmemberfordey427-Jun-07 0:11 
QuestionAcknowledge the message Pinmemberniketha25-Jan-07 12:42 
Generalexe Pinmemberzfd4n13l26-Jul-05 7:44 
GeneralNot working in windows XP Pinmemberchito29-Sep-04 22:09 
GeneralRe: Not working in windows XP PinsussAnonymous26-Oct-04 11:39 
GeneralRe: Not working in windows XP Pinmemberdbdannydb9-Nov-04 12:13 
GeneralRe: Not working in windows XP PinsussAbxi17-Aug-05 14:30 
GeneralRe: Not working in windows XP PinmemberVF2-Jun-06 22:15 
GeneralGreat Job! PinmemberGlenn E. Lanier II6-Aug-04 3:57 
QuestionNot working? PinmemberTCavins3-Aug-04 7:17 
Questionhow to receive net send message? Pinmembervutrunghieu20-Apr-04 15:29 
AnswerRe: how to receive net send message? PinsussRoberto Rivera9-May-04 8:30 
After the message has been "read" or "displayed" you can see it at the event log. Perhaps you could make a program that reads the event log and filters the ones that are "net messages".
 
Regards
 
#1 pickup line of all time: "Hey, does this rag smell like chloroform to you?
Generalmessage spam PinmemberNo Brayn R4-Apr-04 0:56 
QuestionThanks. Can the user login be included? Pinmemberbparent24-Mar-04 5:07 
AnswerRe: Thanks. Can the user login be included? PinmemberGShravanKumar7-Apr-04 18: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 | Mobile
Web04 | 2.8.140921.1 | Last Updated 24 Mar 2004
Article Copyright 2004 by Francisco Prata
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid