问题
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?
回答1:
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).
回答2:
It works with double quotes:
WinExec(PAnsiChar(AnsiString(ExtractFilePath(application.ExeName) + '\winrar.exe A "c:\BACKUP 2016\backup_"' .....
来源:https://stackoverflow.com/questions/12893650/shellexecute-failing-if-spaces-in-path