如果路径中有空格,ShellExecute将失败 [英] ShellExecute failing if spaces in Path

查看:114
本文介绍了如果路径中有空格,ShellExecute将失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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';

对ShellExecute的调用如下:

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);
   ... 

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

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.

有什么想法吗?

推荐答案

使用您的 lpFile 参数,您应将 JobManager 转换为 PChar :

With your lpFile parameter you should cast JobManager as PChar:

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

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

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

这篇关于如果路径中有空格,ShellExecute将失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆