zoukankan      html  css  js  c++  java
  • 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);
                }
  • 相关阅读:
    反编译工具
    3.25Java变量
    标识符
    OMS系统
    java打印方法区别
    注释
    写代码时候要注意的两个点
    python_pracyoce_day1
    SKU和SPU
    文档注释
  • 原文地址:https://www.cnblogs.com/cxeye/p/4238044.html
Copyright © 2011-2022 走看看