NOCLOSE.EXE Win9x CRITICAL bug
Moderators: Hacker, petermad, Stefan2, white
NOCLOSE.EXE Win9x CRITICAL bug
NOCLOSE.EXE twice quoted the command line, and command.com does' nt understand it.
- ghisler(Author)
- Site Admin
- Posts: 50535
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: NOCLOSE.EXE Win9x CRITICAL bug
Sorry, I don't understand the problem. Maybe it helps to put the program in a directory without spaces?
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: NOCLOSE.EXE Win9x CRITICAL bug
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 
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?

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!ghisler(Author) wrote: 2019-10-30, 17:26 UTC Maybe it helps to put the program in a directory without spaces?
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.
- ghisler(Author)
- Site Admin
- Posts: 50535
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: NOCLOSE.EXE Win9x CRITICAL bug
Sorry, I still don't understand the problem. Here is the code of NOCLOSE.EXE, what's wrong?
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.
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;
}
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: NOCLOSE.EXE Win9x CRITICAL bug
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.
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.
Re: NOCLOSE.EXE Win9x CRITICAL bug
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.
Re: NOCLOSE.EXE Win9x CRITICAL bug
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%"
PS. You can execute cmd.exe /? to read about its quoting rules.
Re: NOCLOSE.EXE Win9x CRITICAL bug
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.
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.
Re: NOCLOSE.EXE Win9x CRITICAL bug
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?
Why should we still use noclose.exe? Is there any reason to use it?
Ukrainian Total Commander Translator. Feedback and discuss.
- ghisler(Author)
- Site Admin
- Posts: 50535
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: NOCLOSE.EXE Win9x CRITICAL bug
The idea was that people could replace it with their own command handler for Shift+Enter.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 50535
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: NOCLOSE.EXE Win9x CRITICAL bug
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.
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
https://www.ghisler.com
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 50535
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: NOCLOSE.EXE Win9x CRITICAL bug
I'm moving this to fixed bugs since there was no reply for 2 weeks.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com