Page 1 of 1

Allow launching applications from locations longer than 259

Posted: 2014-01-26, 22:18 UTC
by MarcinW
Currently TC can't start applications from paths longer than 259 chars. It seems that this could be easily improved:

Code: Select all

if Win32Platform = VER_PLATFORM_WIN32_NT then
if Length(FileName) >= MAX_PATH then
  FileName:='\\?\'+FileName;

CreateProcess(PChar(FileName),...)
However, I don't know whether TC uses CreateProcess to launch applications or not.

Regards

Re: Allow launching applications from locations longer than

Posted: 2014-01-27, 01:08 UTC
by white
MarcinW wrote:However, I don't know whether TC uses CreateProcess to launch applications or not.
AFAIK TC uses ShellExecuteEx.

Posted: 2014-01-27, 09:14 UTC
by MVV
AFAIK any Unicode API function supports prefixed paths up to 1023 characters. But is there any reason to keep applications in such deep places? Are you sure that app is able to work correctly in that place?

Posted: 2014-01-27, 10:46 UTC
by MarcinW
ShellExecuteEx doesn't support '\\?\' prefix, however TC could try something like this:

Code: Select all

if Length(FileName) < MAX_PATH then
  ShellExecuteEx(...)
else
if Win32Platform = VER_PLATFORM_WIN32_NT then
  CreateProcess(PChar('\\?\'+FileName),...) {This will work only for executable images}
If the launched file is not an executable, but for example a doc file, CreateProcess returns ERROR_BAD_EXE_FORMAT, so TC could display same error message as for the normal ShellExecuteEx call (ShellExecuteEx returns ERROR_PATH_NOT_FOUND in this case).

MVV wrote:AFAIK any Unicode API function supports prefixed paths up to 1023 characters.
According to my tests, under Windows NT family you can use both ANSI and Unicode APIs with '\\?\' prefix and they works. And MSDN says, that the limit is as large as 32767 chars (+ null) in this case. But this works only with some functions from kernel32.dll, which is a wrapper around ntdll.dll, which passes calls to kernel-mode. AFAIK in the kernel mode all paths use '\\?\' prefix, so such paths can also be passed directly from the user mode.

MVV wrote:But is there any reason to keep applications in such deep places? Are you sure that app is able to work correctly in that place?
I was waiting for this question :) I don't keep anything in such long locations, but sometimes I need/want to test something (for example if app is able to work correctly in that place ;)). Currently I must call CreateProcess to do this.


TC can use long paths almost everywhere, so this small improvement would be very nice.

Regards

Posted: 2014-01-27, 15:12 UTC
by ghisler(Author)
TC has to use ShellExecuteEx to support elevation.

Posted: 2014-01-27, 15:38 UTC
by white
Better error message than "Search path not found!" would be nice..

Posted: 2014-01-27, 15:48 UTC
by MVV
'Access denined' in my case. :)

BTW it is Explorer who shows really dumb message. :D 'Internet security settings don't allow to open one or more files' (approx., translated from Russian).

It seems that ShellExecute really doesn't support long paths.