Run command line code programmatically using C#

前端 未结 3 1839
野趣味
野趣味 2020-12-01 13:14

I\'m using this code run in windows command prompt.. But I need this done programmatically using C# code

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.3

3条回答
  •  感情败类
    2020-12-01 13:33

    You may use the Process.Start method:

    Process.Start(
        @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe",
        @"-pdf ""connection Strings"" ""C:\Users\XXX\Desktop\connection string\DNN"""
    );
    

    or if you want more control over the shell and be able to capture for example the standard output and error you could use the overload taking a ProcessStartInfo:

    var psi = new ProcessStartInfo(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe")
    {
        Arguments = @"-pdf ""connection Strings"" ""C:\Users\XXX\Desktop\connection string\DNN""",
        UseShellExecute = false,
        CreateNoWindow = true
    };
    Process.Start(psi);
    

提交回复
热议问题