In a Powershell environment, is it possible to hide the title bar or at least remove the close button?
I have some scripts that I'd prefer the user not "poke" at while they're running. I've considered running the script as hidden, but then the system will look like it's stuck for a minute or completely done when things are actually still going on under the covers.
You can disable the close button of the Windows console with this script at poshcode.org. However, the user can still close the console from the taskbar, and it doesn't work on console replacements such as ConEmu.
$code = @'
using System;
using System.Runtime.InteropServices;
namespace CloseButtonToggle {
internal static class WinAPI {
[DllImport("kernel32.dll")]
internal static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteMenu(IntPtr hMenu,
uint uPosition, uint uFlags);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DrawMenuBar(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern IntPtr GetSystemMenu(IntPtr hWnd,
[MarshalAs(UnmanagedType.Bool)]bool bRevert);
const uint SC_CLOSE = 0xf060;
const uint MF_BYCOMMAND = 0;
internal static void ChangeCurrentState(bool state) {
IntPtr hMenu = GetSystemMenu(GetConsoleWindow(), state);
DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());
}
}
public static class Status {
public static void Disable() {
WinAPI.ChangeCurrentState(false); //its 'true' if need to enable
}
}
}
'@
Add-Type $code
[CloseButtonToggle.Status]::Disable()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With