• C#- Winform调用BAT例子


      前段时间在工作的时候需要用到,百度了好久后找,可是找到了又希望调用的时候窗体不要显示出来。

      proc.StartInfo.CreateNoWindow = true;
           proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

      这两句能隐藏掉CMD窗口

      最后的代码如下:

               try
                {
                    string str = System.Windows.Forms.Application.StartupPath + "\1.bat";
    
                    string strDirPath = System.IO.Path.GetDirectoryName(str);
                    string strFilePath = System.IO.Path.GetFileName(str);
    
                    string targetDir = string.Format(strDirPath);//this is where mybatch.bat lies
                    proc = new Process();
                    proc.StartInfo.WorkingDirectory = targetDir;
                    proc.StartInfo.FileName = strFilePath;
                    
                    proc.StartInfo.CreateNoWindow = true;
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
    
    
                    MessageBox.Show("执行成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("执行失败 错误原因:" + ex.Message);
                }
  • 相关阅读:
    dd的用法
    od的用法
    Windows 7安装Oracle 10g的方法
    Ubuntu下的iptux和Windows下的飞秋互传文件
    c++ 12
    c++ 11
    c++ 10
    c++ 09
    c++ 08
    c++ 07
  • 原文地址:https://www.cnblogs.com/cxeye/p/4238044.html
Copyright © 2020-2023  润新知