Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShellExecute failing if spaces in Path

I have a Delphi application that uses ShellExecute to call a second Delphi Application on a button press.

The applications are stored on the same server, on the same network share. Their paths are in the format:

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

The call to ShellExecute 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);
   ... 

As we have three office we have copies of the Apps folder on each office server. Each server has the Apps folder on a share mapped to "Z:"

In one of the offices we have discovered a problem where the Applications cannot be found if the paths contain spaces. As the applications are straight copies of each other, and work in the other offices the problem seems to be a machine setting.

Any ideas?

like image 723
Dan Kelly Avatar asked Oct 15 '12 10:10

Dan Kelly


1 Answers

With your lpFile parameter you should cast JobManager as PChar:

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

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

like image 72
kobik Avatar answered Oct 12 '22 09:10

kobik