I launch PowerShell and commands through C#.
Using Windows 10.
Method 1
Process.Start("powershell.exe",
"Write-Host \"Hello, world!\"; timeout 30"
);
Method 2
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();
}
Problem
However the window size is much larger than when launching PowerShell normally.
Are there any commands or launch parameters that can lower the window size?
Instead of forcing a new width and height, I'd like to have it revert to it's original size so it doesn't affect other versions of PowerShell in Windows 7.
Left: C# Process.Start().
Right: Normal
Solutions
I've tried -nologo -noprofile -command
.
I also tried using this window resize
https://stackoverflow.com/a/6485074/6806643
It works in a Console Application, but I can't get it to work in WPF.
Also PowerShell will exit if I try to resize the width by hand.