开发者

net send command program debugging in C#

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
{                开发者_StackOverflow中文版                
    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");
    }                                                  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜