gpt4 book ai didi

powershell - 在powershell中隐藏标题栏

转载 作者:行者123 更新时间:2023-12-03 09:53:28 25 4
gpt4 key购买 nike

在 Powershell 环境中,是否可以隐藏标题栏或至少删除关闭按钮?

我有一些脚本,我希望用户在运行时不要“戳”它们。我曾考虑将脚本运行为隐藏状态,但是当事情实际上仍在幕后进行时,系统看起来会卡住一分钟或完全完成。

最佳答案

您可以使用 this script at poshcode.org 禁用 Windows 控制台的关闭按钮。 .但是,用户仍然可以从任务栏关闭控制台,并且它不适用于 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()

关于powershell - 在powershell中隐藏标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19642149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com