代码之家  ›  专栏  ›  技术社区  ›  Kyle West

我可以使用命令行,还是从托管代码运行批处理文件?(.net)

  •  5
  • Kyle West  · 技术社区  · 16 年前

    就像主题所说的那样。我希望能够从控制台应用程序运行iisreset、批处理文件等。我能/怎么做?

    3 回复  |  直到 13 年前
        1
  •  6
  •   Otávio Décio    16 年前

    这是完全可能的,例如:

     System.Diagnostics.Process.Start(@"C:\listfiles.bat");
    
        2
  •  3
  •   Ric Tokyo    16 年前

    检查以下示例: C# Station

    using System;
    using System.Diagnostics;
    
    namespace csharp_station.howto
    {
        /// <summary>
        /// Demonstrates how to start another program from C#
        /// </summary>
        class ProcessStart
        {
            static void Main(string[] args)
            {
                Process notePad = new Process();
    
                notePad.StartInfo.FileName   = "notepad.exe";
                notePad.StartInfo.Arguments = "ProcessStart.cs";
    
                notePad.Start();
            }
        }
    }
    
        3
  •  2
  •   Dimi Takis    16 年前

    您也可以这样做:

      System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
      info.UseShellExecute = true;
      info.FileName = "iisreset";
      System.Diagnostics.Process.Start(info);
    
    
    
      Console.ReadLine();