C# 连接另一台电脑共享文件夹时显示net 不是内部或外部命令,也不是可运行的程序或批处理文件

flower_ 发布于 2016/09/26 10:36
阅读 584
收藏 0
  public static bool Connect(string remoteHost, string userName, string passWord)
        {
            bool Flag = false;
            Process proc = new Process();
            try
            {
                proc.StartInfo.FileName = "cmd.exe";
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardInput = true;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
             //   string dosLine1 = "explorer " + remoteHost + " " + passWord + " /user:" + userName;
             //   proc.StandardInput.WriteLine(dosLine1);
                string dosLine = "net"+"use" + remoteHost + " " + passWord + " /user:" + userName;
                proc.StandardInput.WriteLine(dosLine);
                proc.StandardInput.WriteLine("exit");
                while (!proc.HasExited)
                {
                    proc.WaitForExit(1000);
                }

                string errormsg = proc.StandardError.ReadToEnd();
             //   me.WirteDayLog("msg:" + errormsg);
                MessageBox.Show(errormsg);
                proc.StandardError.Close();
                if (String.IsNullOrEmpty(errormsg))
                {
                    Flag = true;
                }
            }
            catch (Exception ex)
            {
             //   WriteLog.WirteDayLog(ex.ToString());
                MessageBox.Show(ex.ToString());
                throw ex;
            }
            finally
            {
                proc.Close();
                proc.Dispose();
            }
            return Flag;

        }

刚学习C#,不太懂,求大神帮忙看看。。。

加载中
0
张亦俊
张亦俊
你打开cmd敲net试试咯。有可能是权限不够,也有可能是没装。
f
flower_
cmd 可以连上
返回顶部
顶部