ShellExecute error if spaces in the path

I have a Delphi application that uses ShellExecute to invoke a second Delphi application when a button is clicked.

Applications are stored on the same server on the same network resource. Their paths are in the format:

const JobManager = 'Z:\Apps\Application 1\Application1.exe'; FeeManager = 'Z:\Apps\Application 2\Application2.exe'; 

A ShellExecute call is made as follows:

 rh := FindWindow(PChar('TMF'), PChar('Edit Job Details')); if rh = 0 then begin ShellExecute(Handle, 'open', JobManager, nil, nil, SW_SHOWNORMAL); ... 

Since we have three offices, we have copies of the Apps folder on each office server. On each server there is an โ€œApplicationsโ€ folder for the share associated with โ€œZ:โ€

In one of the offices, we found a problem when applications cannot be found if the paths contain spaces. Since applications are direct copies of each other and work in other offices, the problem seems to be a machine.

Any ideas?

+4
source share
2 answers

With the lpFile parameter lpFile you should use the JobManager as a PChar :

 ShellExecute(Handle, 'open', PChar(JobManager), nil, nil, SW_SHOWNORMAL); 

Note that the verb open parameter is also not needed, and you can pass nil the lpOperation parameter (by default).

+5
source

It works with double quotes:

 WinExec(PAnsiChar(AnsiString(ExtractFilePath(application.ExeName) + '\winrar.exe A "c:\BACKUP 2016\backup_"' ..... 
-2
source

Source: https://habr.com/ru/post/1439783/


All Articles