1 回答

TA贡献1821条经验 获得超4个赞
我玩过这个。也许还有其他一些方法可以做到这一点,但这也有效。由于您需要一些初始设置,我认为您需要使用EnvironmentVariables,如果这样做,您还需要添加
startInfo.UseShellExecute = false;
所以一个可行的例子是
static void Main(string[] args)
{
OpenPowerShell(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
}
static void OpenPowerShell(string path)
{
ProcessStartInfo startInfo = new ProcessStartInfo(path);
startInfo.UseShellExecute = false;
startInfo.EnvironmentVariables.Add("RedirectStandardOutput", "true");
startInfo.EnvironmentVariables.Add("RedirectStandardError", "true");
startInfo.EnvironmentVariables.Add("UseShellExecute", "false");
startInfo.EnvironmentVariables.Add("CreateNoWindow", "true");
Process.Start(startInfo);
}
或者,如果您对另一个窗口没问题,只需:
static void Main(string[] args)
{
OpenPowerShell(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
}
static void OpenPowerShell(string path)
{
Process.Start(path);
}
- 1 回答
- 0 关注
- 230 浏览
添加回答
举报