How to start a process in the same folder as its executable

痞子三分冷 提交于 2019-12-01 00:06:47

问题


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();
}

回答1:


I guess you mean ProcessStartInfo.WorkingDirectory Property




回答2:


Just set the WorkDirectory property.

process.StartInfo.WorkingDirectory = Path.GetDirectoryName(application.Filename);



回答3:


Use process.StartInfo.WorkingDirectory = pathToTheFolder;.



来源:https://stackoverflow.com/questions/2972953/how-to-start-a-process-in-the-same-folder-as-its-executable

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