mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Ignore failure attempting to set console window title (#16948)
This commit is contained in:
@@ -2494,6 +2494,8 @@ namespace Microsoft.PowerShell
|
||||
return consoleTitle.ToString();
|
||||
}
|
||||
|
||||
private static bool s_dontsetConsoleWindowTitle;
|
||||
|
||||
/// <summary>
|
||||
/// Wraps Win32 SetConsoleTitle.
|
||||
/// </summary>
|
||||
@@ -2505,12 +2507,27 @@ namespace Microsoft.PowerShell
|
||||
/// </exception>
|
||||
internal static void SetConsoleWindowTitle(string consoleTitle)
|
||||
{
|
||||
if (s_dontsetConsoleWindowTitle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool result = NativeMethods.SetConsoleTitle(consoleTitle);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
int err = Marshal.GetLastWin32Error();
|
||||
|
||||
// ERROR_GEN_FAILURE is returned if this api can't be used with the terminal
|
||||
if (err == 0x1f)
|
||||
{
|
||||
tracer.WriteLine("Call to SetConsoleTitle failed: {0}", err);
|
||||
s_dontsetConsoleWindowTitle = true;
|
||||
|
||||
// We ignore this specific error as the console can still continue to operate
|
||||
return;
|
||||
}
|
||||
|
||||
HostException e = CreateHostException(err, "SetConsoleWindowTitle",
|
||||
ErrorCategory.ResourceUnavailable, ConsoleControlStrings.SetConsoleWindowTitleExceptionTemplate);
|
||||
throw e;
|
||||
|
||||
Reference in New Issue
Block a user