【发布时间】:2017-08-13 05:45:54
【问题描述】:
我通过 C# 启动 PowerShell 和命令。
使用 Windows 10。
方法一
Process.Start("powershell.exe",
"Write-Host \"Hello, world!\"; timeout 30"
);
方法二
using (Process ps = new Process())
{
ps.StartInfo.UseShellExecute = false;
ps.StartInfo.Verb = "runas";
ps.StartInfo.CreateNoWindow = false;
ps.StartInfo.RedirectStandardOutput = false;
ps.StartInfo.FileName = "powershell.exe";
ps.StartInfo.Arguments = "Write-Host \"Hello, world!\"; timeout 30";
ps.Start();
ps.WaitForExit();
ps.Close();
}
问题
但是窗口大小比正常启动 PowerShell 时要大得多。
有没有可以减小窗口大小的命令或启动参数?
我不想强制使用新的宽度和高度,而是让它恢复到原来的大小,这样它就不会影响 Windows 7 中其他版本的 PowerShell。
解决方案
我试过-nologo -noprofile -command。
我也试过用这个窗口调整大小
https://stackoverflow.com/a/6485074/6806643
它在控制台应用程序中工作,但我无法让它在 WPF 中工作。
如果我尝试手动调整宽度,PowerShell 也会退出。
【问题讨论】:
-
How to set the height of a window using c#? 的可能重复项,或者您可以尝试类似
ps.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;的内容 -
看看
gci HKCU:/console/%SystemRoot%_Sys* -
@GeorgeAlexandria 它在控制台应用程序中工作,但我无法让它在 WPF 中工作。它调整了窗口大小,但字体大小仍然很大。
-
我建议将此信息添加到您的问题中:调整窗口大小和字体。
-
@GeorgeAlexandria 我用一些新信息更新了这个问题。
标签: c# powershell