如何在与其可执行文件相同的文件夹中启动进程

Kir*_*ril 9 c# directory executable process

我正在尝试以编程方式启动应用程序,但它始终在我的应用程序的文件夹中运行...例如:

如果我的应用程序位于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();
}
Run Code Online (Sandbox Code Playgroud)

djd*_*d87 6

只需设置WorkDirectory属性即可.

process.StartInfo.WorkingDirectory = Path.GetDirectoryName(application.Filename);
Run Code Online (Sandbox Code Playgroud)


Fem*_*ref 6

使用process.StartInfo.WorkingDirectory = pathToTheFolder;.