如果Path中有空格,则ShellExecute失败

Dan*_*lly 5 delphi windows-xp shellexecute filepath

我有一个Delphi应用程序,它使用ShellExecute在按下按钮上调用第二个Delphi应用程序.

应用程序存储在同一服务器上,位于同一网络共享上.他们的路径采用以下格式:

const
   JobManager = 'Z:\Apps\Application 1\Application1.exe';
   FeeManager = 'Z:\Apps\Application 2\Application2.exe';
Run Code Online (Sandbox Code Playgroud)

对ShellExecute的调用如下:

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

由于我们有三个办公室,我们在每个办公室服务器上都有Apps文件夹的副本.每个服务器的共享上的Apps文件夹映射到"Z:"

在其中一个办公室,我们发现了一个问题,如果路径包含空格,则无法找到应用程序.由于应用程序是彼此的直接副本,并且在其他办公室工作,问题似乎是机器设置.

有任何想法吗?

kob*_*bik 5

使用您的lpFile参数,您应该转换JobManagerPChar:

ShellExecute(Handle, 'open', PChar(JobManager), nil, nil, SW_SHOWNORMAL);
Run Code Online (Sandbox Code Playgroud)

请注意,open也不需要动词参数,您可以nil使用lpOperation参数传递(默认).