Page 1 of 1

disable x button

Posted: 18 Dec 2013 10:05
by carlos
Hello.
Some can want disable the x button.
This is the executable:

Code: Select all

@Echo Off
Call :DisableX
disablex.exe
Pause
Goto :Eof

:DisableX
Rem Script made using BHX { code.google.com/p/bhx }
SetLocal EnableExtensions
For %%# In ("disablex.ex_") Do Set "bin=%%~f#"
For %%# In ("disablex.exe") Do Set "exp=%%~f#"
Del /A /F "%bin%" "%bin%.da" "%exp%" >Nul 2>&1
For %%# In (
4D53434600000000E4010000000000002C000000000000000301010001000000
0000000049000000010001000006000000000000000092432A66200064697361
626C65782E657865002BDDCAD193010006434BF38D9AC0C0CCC0C0C002C4FFFF
3330EC6080000706C2A00188F9E477F1316CE13CABB883D1E7AC62484666B142
41517E7A5162AE4272625E5E7E894252AA4251699E42669E828B7FB0426E7E4A
AA1E2F2F970AD48C005706061F462614731F30F0337333B2A188B90800091056
80BA0EC46682B89B810141331840C4455E3080FD055628804CC32908009A1740
845F490501407365F0C8EB95A4569400E90E988398A018D569097A2989258920
0E23D4EF4CC89E85C7D50172DD19DAF9B4F10D079031E1452490EC74FDD3FC83
81BF459D019A1402BA5DFF04BC70034BFDD8017244C08E840F60F11F012FCC80
FC9387C1663080CD58FBFFFF7F88BE174A40B2F908CBC9C3607BFEAB06283880
E908281D03A5531488496BA38036204701C1EE5080A4DB1224B1154076041037
20895D01B25314B09B37152ABE19481F86B2EF2B1096CB4E2DCA4BCD3136D24B
C9C90172DD534B9CF3F38AF37352C333F352F2CB194A8B538B9065832B8B4B52
737D53F34A817CD7BCC4A49C5410C71328C8905B5C965C5402559B5A9159321A
CD380100
) Do >>"%bin%.da" (Echo For b=1 To Len^("%%#"^) Step 2
Echo WScript.StdOut.Write Chr^(CByte^("&H"^&Mid^("%%#",b,2^)^)^)
Echo Next)
Cscript.exe /B /E:vbs "%bin%.da" >"%bin%"
Expand.exe "%bin%" "%exp%" >Nul 2>&1
Del /A /F "%bin%" "%bin%.da" >Nul 2>&1
Goto :Eof


c source
disablex.c

Code: Select all

#include <windows.h>
void main(void) {
  HWND hWnd;
  HMENU hMenu;
  if (((hWnd = GetConsoleWindow()) != NULL)) {
    hMenu = GetSystemMenu(hWnd, FALSE);
    EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
  }
}

Re: disable x button

Posted: 18 Dec 2013 18:11
by foxidrive
It works fine, carlos. Ta.

Re: disable x button

Posted: 17 Feb 2025 16:38
by miskox
I find this disablex.exe very useful now. But I have a problem: I would like to check if disablex.exe is in the path so I would need something like

Code: Select all

disablex.exe /v
/v version info or something - so running the .exe does not disable the 'X'. If disablex.exe is not in the path I get errorlevel=9009 but I want to run it just for some accounts.

Anyone can change the source and make a new .exe, please (this .exe has 1536 bytes - so as small as possible would be great)?

Thanks.
Saso

Re: disable x button

Posted: 18 Feb 2025 10:24
by aGerman
I think even with some trickery I don't get it that lightweight again. (Antonio might be able using Assembler though.)
However, you can always check if an executable is found in the PATH. Use the ~$path: modifier of FOR variables.

Code: Select all

for %%i in ("whatever.exe") do if "%%~$path:i"=="" echo Not found.
Steffen

Re: disable x button

Posted: 18 Feb 2025 11:20
by miskox
Thanks Steffen!

I don't think there is a need for an assembler code. C would do - even if .exe is bigger in size.

Maybe just adding an IF:

Code: Select all

if parameter1="1" then exit 99
So if I execute

Code: Select all

disableX.exe 1
if "%errorlevel%"=="99" echo DISABLEX found.

Code: Select all

set disablex_exists=0
disableX.exe 1
if "%errorlevel%"=="99" set disablex_exists
if "%username%"=="JOHN" if "%disablex_exists%"=="1" disableX.exe

Something like that - as simple as possible because there is no need to complicate.

Thanks (I don't 'speak' C* and I don't have an option to make an .exe).

Saso

Re: disable x button

Posted: 18 Feb 2025 13:49
by aGerman
there is no need to complicate
But this makes it overly complicated. You can check the existence of the tool and you have to check the user name anyway, so you can just contitionally call the tool. I still don't get the point why the update of the tool is needed.

Nevermind... Pass 1 and you'll get return value 99 as per your request.
disablex.zip
(1.39 KiB) Downloaded 291 times

FWIW I had to explicitly run the tool in a console. Of course it has no effect in a terminal.

Steffen

Re: disable x button

Posted: 19 Feb 2025 01:45
by miskox
Thanks Steffen.

Of course code could be shortened:

Code: Select all

disableX.exe 1
set errlev=%errorlevel%
if "%errlev%"=="99" if "%username%"=="JOHN" disableX.exe
if "%errlev%"=="99" if "%username%"=="JANE" disableX.exe
if "%errlev%"=="99" if "%username%"=="MARY" disableX.exe
if "%errlev%"=="99" if "%username%"=="JILL"  disableX.exe
if "%errlev%"=="99" if "%username%"=="MIKE" disableX.exe
or

Code: Select all

set user_list="#JOHN#JANE#MARY#JILL#MIKE#"
call set tmp_str=%%user_list:#%username%#=X%%
disableX.exe 1
if "%errorlevel%"=="99" if not "%tmp_str%"=="%user_list%" disableX.exe
Thanks again.
Saso

Re: disable x button

Posted: 19 Feb 2025 10:12
by aGerman
Calling a non-existing tool will make the CMD to throw an error. Regardless if you call it with or without an argument.
So isn't that the same thing? :

Code: Select all

set user_"list=#JOHN#JANE#MARY#JILL#MIKE#"
call set "tmp_str=%%user_list:#%username%#=X%%"
if not "%tmp_str%"=="%user_list%" disableX.exe
If you want to get rid of the error message either check if the tool exists (using the FOR loop I wrote above if you expect the tool in the PATH environment, or using IF EXIST if in a certain directory), or redirect the error message using 2>NUL.

Steffen

Re: disable x button

Posted: 19 Feb 2025 11:52
by miskox
I checked your FOR solution. It is great. And as you mention I can add additional check for the current directory.

The idea with the 2>nul is also great.

Thanks for the help.
Saso

Re: disable x button

Posted: 19 Feb 2025 13:25
by aGerman
miskox wrote:
19 Feb 2025 11:52
And as you mention I can add additional check for the current directory.
You can explicitly add the current work dir to PATH for the running cmd session.

Code: Select all

set "path=.;%path%"
After that, the expansion using ~$path: takes it into account.

Steffen

Re: disable x button

Posted: 20 Feb 2025 00:54
by miskox
Thanks again!

You always have a clever solution (short and efficient).

Saso