如何在与其可执行文件相同的文件夹中启动进程
我试图以编程方式启动一个应用程序,但它总是在我的应用程序的文件夹中运行它...例如:
如果我的应用程序位于 C:\MyApp\myapp.exe 中,另一个应用程序位于 C:\ OtherApp\otherapp.exe,如何在其他应用程序所在的文件夹中启动其他应用程序,而不是在我的应用程序所在的文件夹中启动?
这是我启动另一个应用程序的方法:
private void StartApp(OtherApp application)
{
Process process = new Process();
process.StartInfo.FileName = application.FileName;
process.StartInfo.Arguments = application.AppName;
process.Start();
}
I'm trying to start an application programatically, but it always runs it in the folder of my application... For example:
If my app is located in C:\MyApp\myapp.exe and the other app is in C:\OtherApp\otherapp.exe, how can I start the other app in the folder in which it resides, rather than in the folder where my app resides?
Here is how I start the other app:
private void StartApp(OtherApp application)
{
Process process = new Process();
process.StartInfo.FileName = application.FileName;
process.StartInfo.Arguments = application.AppName;
process.Start();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你的意思是 ProcessStartInfo.WorkingDirectory 属性
I guess you mean ProcessStartInfo.WorkingDirectory Property
使用
process.StartInfo.WorkingDirectory = pathToTheFolder;
。Use
process.StartInfo.WorkingDirectory = pathToTheFolder;
.只需设置 WorkDirectory 属性即可。
Just set the WorkDirectory property.