NOCLOSE.EXE Win9x CRITICAL bug

Bug reports will be moved here when the described bug has been fixed

Moderators: sheep, Hacker, Stefan2, white

Post Reply
Isica
Junior Member
Junior Member
Posts: 38
Joined: 2013-09-24, 05:07 UTC

NOCLOSE.EXE Win9x CRITICAL bug

Post by Isica »

NOCLOSE.EXE twice quoted the command line, and command.com does' nt understand it.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38783
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by ghisler(Author) »

Sorry, I don't understand the problem. Maybe it helps to put the program in a directory without spaces?
Author of Total Commander
http://www.ghisler.com

Isica
Junior Member
Junior Member
Posts: 38
Joined: 2013-09-24, 05:07 UTC

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by Isica »

So you try to run under Win9x, for example, "dir" and Shift+Enter. And then try to do the same with the fixed noclose.exe, and feel the difference ;-)
ghisler(Author) wrote:
2019-10-30, 17:26 UTC
Maybe it helps to put the program in a directory without spaces?
totalcmd.exe itself adds all the necessary quotation marks, and noclose.exe receives a ready-to-use command line, that does not need any modifications!
PS
I'm curious: why did you even add this proxy-process? What prevents you from invoking command.com/cmd.exe with the /K switch directly from TC?
Last edited by Isica on 2019-11-01, 11:22 UTC, edited 1 time in total.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38783
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by ghisler(Author) »

Sorry, I still don't understand the problem. Here is the code of NOCLOSE.EXE, what's wrong?

Code: Select all

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	char cmdlinea[32768];
	WCHAR cmdlinew[32768];
	PROCESS_INFORMATION pi;
	memset(&pi,0,sizeof(pi));

	OSVERSIONINFO vx;
	memset(&vx,0,sizeof(vx));
	vx.dwOSVersionInfoSize=sizeof(vx);
	GetVersionEx(&vx);
	if (vx.dwPlatformId==VER_PLATFORM_WIN32_NT) {
		STARTUPINFOW si;
		memset(&si,0,sizeof(si));
		si.cb=sizeof(si);
		si.wShowWindow=nCmdShow;
		si.dwFlags=1;
		wcscpy(cmdlinew,L"cmd.exe /K \"");
		WCHAR* p=GetCommandLineW();
		// skip program itself!
		if (p[0]=='"') {
			p=wcschr(p+1,'"');
			if (p==NULL)
				return 1;
			p++;
		} else {
			p=wcschr(p,' ');
			if (p==NULL)
				return 1;
		}
		while (p[0]==' ')
			p++;
		if (p[0]=='/' && p[1]=='C' && p[2]==' ')
			p+=3;
		wcsncat(cmdlinew,p,sizeof(cmdlinew)/2-2);
		wcsncat(cmdlinew,L"\"",sizeof(cmdlinew)/2-1);
		CreateProcessW(NULL,cmdlinew,NULL,NULL,false,CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS
		  | CREATE_DEFAULT_ERROR_MODE,NULL,NULL,&si,&pi);
	} else {
		STARTUPINFO si;
		memset(&si,0,sizeof(si));
		si.cb=sizeof(si);
		si.wShowWindow=nCmdShow;
		si.dwFlags=1;
		strcpy(cmdlinea,"command.com /K \"");
		strncat(cmdlinea,lpCmdLine,sizeof(cmdlinea)-2);
		strncat(cmdlinea,"\"",sizeof(cmdlinea)-1);
		CreateProcess(NULL,cmdlinea,NULL,NULL,false,CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS
		  | CREATE_DEFAULT_ERROR_MODE,NULL,NULL,&si,&pi);
	}

	if (pi.hProcess) {
		WaitForSingleObject(pi.hProcess,INFINITE);
		CloseHandle(pi.hProcess);
	}
	if (pi.hThread)
		CloseHandle(pi.hThread);
	return 0;
}
Noclose.exe is a drop in replacement for noclose.pif, which prevented command.com from closing. You are right that it's not really necessary any more.
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8434
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by MVV »

AFAIK, command line after /K must not be double-quoted for Win9x, it is only a WinNT stupid cmd.exe's requirement. So you should just append command line to command.com /K for Win9x and at the same time you should append double-quoted command line to cmd.exe /K. And, there are still conditions that blind double-quoting for WinNT may cause fails.

But here I think that "dir" in TC command line should produce same results like in cmd.exe command line, so it is quite expected that quoted interpreter command name fails - it must not be quoted.

Isica
Junior Member
Junior Member
Posts: 38
Joined: 2013-09-24, 05:07 UTC

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by Isica »

MVV wrote:
2019-11-05, 06:47 UTC
it is only a WinNT stupid cmd.exe's requirement.
No, cmd doesn't require that either!

2ghisler(Author)
I'm repeat: the command line that noclose receives from TC is completely ready-for-use and does not require any additional processing!
That is, noclose should only add the /K prefix, and that’s it.

User avatar
MVV
Power Member
Power Member
Posts: 8434
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by MVV »

Isica wrote:
2019-11-07, 23:59 UTC
No, cmd doesn't require that either!
Things are complicated with cmd.exe. It assumes that the passed command line is double-quoted in some cases and removes "outer" quotes, so if you aren't aware of its stupid syntax, you may get errors.

E.g. try executing following command line:

Code: Select all

cmd.exe /k "%COMMANDER_EXE%" /n /i="%COMMANDER_INI%"
You will get an error because cmd.exe cuts first and last quote and gets incorrect command line. So in this case you have to add outer quotes to passed command line.

PS. You can execute cmd.exe /? to read about its quoting rules.

Isica
Junior Member
Junior Member
Posts: 38
Joined: 2013-09-24, 05:07 UTC

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by Isica »

Yes, you are right, I missed this moment.
Then do it right:
command.com /K <command-line>
cmd.exe /S /K "<command-line>"


That is, for cmd, you need to stupidly enclose the command line in quotation marks, and that’s it. But you should NOT go into the meaning of the command line and try to correct it.

User avatar
MaxX
Power Member
Power Member
Posts: 690
Joined: 2012-03-23, 18:15 UTC
Location: Earth

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by MaxX »

Hm. I use "cmd.exe /K <command-line>" and have no problems.
Why should we still use noclose.exe? Is there any reason to use it?

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38783
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by ghisler(Author) »

The idea was that people could replace it with their own command handler for Shift+Enter.
Author of Total Commander
http://www.ghisler.com

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38783
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by ghisler(Author) »

Could someone test this please? It should be fixed since beta 9:
11.12.19 Fixed: NOCLOSE.EXE: Do not quote command after /K when using command.com (32)

TC should call command.com without quotes on Win9x/ME, the behaviour on Windows NT based system is unchanged.
Author of Total Commander
http://www.ghisler.com

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 38783
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: NOCLOSE.EXE Win9x CRITICAL bug

Post by ghisler(Author) »

I'm moving this to fixed bugs since there was no reply for 2 weeks.
Author of Total Commander
http://www.ghisler.com

Post Reply