• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
nicesoft
博客园    首页    新随笔    联系   管理    订阅  订阅

C#执行cmd

            string cmdtext = "net use u: \\\\192.168.0.44\\src \"" + user + "\" /user:" + pwd;
            Process MyProcess = new Process();
            //设定程序名
            MyProcess.StartInfo.FileName = "cmd.exe";
            //关闭Shell的使用
            MyProcess.StartInfo.UseShellExecute = false;
            //重定向标准输入
            MyProcess.StartInfo.RedirectStandardInput = true;
            //重定向标准输出
            MyProcess.StartInfo.RedirectStandardOutput = true;
            //重定向错误输出
            MyProcess.StartInfo.RedirectStandardError = true;
            //设置不显示窗口
            MyProcess.StartInfo.CreateNoWindow = true;
            //执行VER命令
            MyProcess.Start();
            MyProcess.StandardInput.WriteLine(cmdtext);
            MyProcess.StandardInput.WriteLine("exit");
            //从输出流获取命令执行结果,
            //string exepath = Application.StartupPath;
            //把返回的DOS信息读出来
            String StrInfo = MyProcess.StandardOutput.ReadToEnd();
            Console.WriteLine(StrInfo);

posted @ 2011-12-20 09:19  nicesoft  阅读(6012)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3