如何强制Powershell控制台进程退出并继续使用C#?

时间:2015-11-03 23:03:39

标签: c# powershell

在进程中从C#运行Powershell脚本。脚本运行正常,但控制台只是挂在那里等待。

这是我的代码:

 public static int RunPowershellScript(string ps)
    {
        int errorLevel;
        ProcessStartInfo processInfo;
        Process process;
        var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        processInfo = new ProcessStartInfo("powershell.exe", "-File " + ps);
        processInfo.CreateNoWindow = false;
        processInfo.UseShellExecute = false;

        process = Process.Start(processInfo);
        process.WaitForExit();

        errorLevel = process.ExitCode;
        process.Close();

        return errorLevel;
    }

我需要做些什么来告诉这个方法在脚本完成后才离开?

谢谢!

0 个答案:

没有答案