zoukankan      html  css  js  c++  java
  • C#调用net.exe发送消息

    默认情况下,WinXP SP2的Messenger服务是禁止的,如果需要使用必须先启动该服务。

            //发消息
            private void NetSendMsg(string strIp, string strHostname, string strMsg)
            {
                try
                {
                    Process sendprocess =new  Process();
                    sendprocess.StartInfo.FileName = "net.exe";
                    sendprocess.StartInfo.Arguments = "send " + strIp + " " + strMsg;
                    sendprocess.StartInfo.UseShellExecute = false;
                    sendprocess.StartInfo.RedirectStandardOutput = true;
                    sendprocess.StartInfo.RedirectStandardError = true;
                    sendprocess.StartInfo.CreateNoWindow = true;
                    sendprocess.Start();

                    string strSend = sendprocess.StandardOutput.ReadToEnd();

                    if (strSend.IndexOf("消息已经送到 "+strIp+"。") != -1)
                    {
                        lb_Info.Items.Add(DateTime.Now.ToLongTimeString() + "发消息到 " + strHostname + ":" + strMsg);
                    }
                    else
                    {
                        lb_Info.Items.Add("发消息到" + strHostname + "失败!"+DateTime.Now.ToLongTimeString());
                    }
                   
                }
                catch(Exception ex)
                {
                    lb_Info.Items.Add(ex.Message+DateTime.Now.ToLongTimeString()+"发消息到" + strHostname + "失败!");
                }
            }

  • 相关阅读:
    java环境变量配置(Windows & Linux)
    转行自学编程的前提条件和能力
    IntelliJ IDEA 视频教程
    小孩都懂得用“头衔”来包装自己了,那么你呢?
    自创“乒乓球自嗨玩法”
    什么是npm以及npm基本命令
    hexo本地搭建以及在github远程部署
    如何下载Java-配置环境全教程
    图的存储结构以及遍历
    二叉树的存储结构以及遍历
  • 原文地址:https://www.cnblogs.com/mossan/p/749664.html
Copyright © 2011-2022 走看看