DisableCmdX.ahk - 禁用CMD窗口的关闭按钮

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: arcticir, tmplinshi

tmplinshi
Posts: 1557
Joined: 01 Oct 2013, 14:57

DisableCmdX.ahk - 禁用CMD窗口的关闭按钮

03 Nov 2014, 03:50

Code: Select all

;@Ahk2Exe-SetDescription 禁用CMD窗口的关闭按钮
;@Ahk2Exe-SetVersion 1.0.0.0
;@Ahk2Exe-SetConsoleSubsys

#NoEnv
#NoTrayIcon
#SingleInstance, off
SetBatchLines -1

; ---------------------------------------------------------------

If 1 in /?,-h,--help,-?
	Help()
Else If 1 = -r
	EnableCmdX()
Else
	DisableCmdX()
Return

; ---------------------------------------------------------------

DisableCmdX() {
	hWnd := DllCall("GetConsoleWindow", "UPtr")
	hSysMenu := DllCall("GetSystemMenu", "Int", hWnd, "Int", FALSE)
	DllCall("RemoveMenu", "Int", hSysMenu, "UInt", 0xF060, "Uint", 0) ; SC_CLOSE=0xF060, MF_BYCOMMAND=0
	DllCall("DrawMenuBar", "Int", hWnd)
}

EnableCmdX() {
	hWnd := DllCall("GetConsoleWindow", "UPtr")
	DllCall("GetSystemMenu", "Int", hWnd, "Int", TRUE)
	DllCall("DrawMenuBar", "Int", hWnd)
}

Help() {
	FileAppend, %   "禁用CMD窗口的关闭按钮" "`n"
	              . "`n"
	              . "用法: " A_ScriptName " [-r]" "`n"
	              . "  -r 恢复关闭按钮" "`n"
	          , CONOUT$
}
注:要用新版的 ahk2exe 编译为命令行程序后再使用。

使用方法:直接在 cmd 窗口或者批处理文件中执行 DisableCmdX.exe。加上 -r 参数则恢复关闭按钮。

相关链接:
mil0t
Posts: 4
Joined: 28 Sep 2014, 06:29

Re: DisableCmdX.ahk - 禁用CMD窗口的关闭按钮

01 Jun 2015, 22:55

感谢tmplinshi分享,CMD的窗口不同于标准Windows窗口,有很多特别之处,各版本的系统还有区别。

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 39 guests