net send command program debugging in C#

Posted by riad on Stack Overflow See other posts from Stack Overflow or by riad
Published on 2010-06-01T05:42:52Z Indexed on 2010/06/01 5:53 UTC
Read the original article Hit count: 277

Filed under:

Dear all, I write a program to execute and send msg using windows net send command.Its working fine for single receptor.But the problem happen when i want to send message in many receptors. i use a for loop to take receptor name from a list box. Here all message go to the first receptor.The problem happen on process execution.So far i guess the process is not clear or dead on the time.

Can any body guide me how i can send the msg to multiple users at a time?

my code below:

string sendingMessage = messageRichTextBox.Text;          
string[] recepentAddressArray = new string[recepentAddressListBox.Items.Count];
for (int j = 0; j < recepentAddressListBox.Items.Count; j++) // Getting  address from list box
{                                
    recepentAddressArray[j] = recepentAddressListBox.Items[j].ToString();
    string recepantAddress = recepentAddressArray[j];               
    try
    {
        string strLine = "net send " + recepantAddress + " " + sendingMessage + " >C:netsend.log";
        FileStream fs = new FileStream("c:netsend.bat", FileMode.Create, FileAccess.Write);
        StreamWriter streamWriter = new StreamWriter(fs);
        streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        streamWriter.Write(strLine);
        streamWriter.Flush();
        streamWriter.Close();
        fs.Close();

        Process p = new Process();
        p.StartInfo.FileName = "C:netsend.bat";
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        p.Start();
        p.WaitForExit();
        p.Close();

        FileStream fsOutput = new FileStream("C:netsend.log", FileMode.Open, FileAccess.Read);
        StreamReader reader = new StreamReader(fsOutput);
        reader.BaseStream.Seek(0, SeekOrigin.Begin);
        string strOut = reader.ReadLine();
        reader.Close();
        fsOutput.Close();
    }
    catch (Exception)
    {
        MessageBox.Show("ERROR");
    }                                                  
}

© Stack Overflow or respective owner

Related posts about c#4.0