ShellExecute failing if spaces in Path

别来无恙 提交于 2021-02-07 14:56:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!