通过 ShellExecute 调用应用程序时,未读取应用程序配置文件
我有一个 .NET 应用程序,它是使用 ShellExecute 通过 Delphi 程序启动的。不幸的是,当以这种方式启动时,应用程序似乎无法正确读取其 app.config 文件,就好像该文件不存在一样。
我尝试在其他场景中测试该应用程序,例如从工作目录设置为不同文件夹的快捷方式调用,并且运行良好。
[编辑]Environment.CurrentDirectory 属性返回Delphi 程序的目录。
任何想法将非常感激。
干杯,
詹姆斯
I have a .NET application that is launched via a Delphi program using ShellExecute. Unfortunately when launched in this manner, the application does not seem to be reading its app.config file correctly, as if the file did not exist.
I have tried testing the application in other scenarios, e.g. calling from a shortcut with the the working directory set to a different folder and it runs fine.
[Edit]The Environment.CurrentDirectory property returns the directory of the Delphi program.
Any ideas would be really appreciated.
Cheers,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,您生成的进程无法处理工作目录不是它自己的事实。
您可以使用 CreateProcess() 打开该文件。我有一个等待的小例子(但你可以将其剪掉):
添加了一些缺少的实用函数:
Apparently the process you spawn cannot handle the fact that the working directory is not it's own.
You could open the file using CreateProcess(). I have a small example with waiting for (but you can clip that out):
Added some missing utility functions:
嗯,我研究了一下,似乎没有一个既简单又优雅的解决方案。
最简单的方法似乎是调用中间 .NET 程序,然后通过 Process.Start 运行目标应用程序并传递参数。并不理想,但它比我迄今为止找到的其他解决方案更简单。
Well I researched it a bit and there does not appear to be a solution that is both simple and elegant.
The easiest way round it seems to be to call an intermediate .NET program that then runs the target application via Process.Start and passes the parameters on. Not ideal but it's simpler than the other solutions I have found so far.