在不同的上下文中从C#运行应用程序

在不同的上下文中从C#运行应用程序,c#,.net-4.6.2,C#,.net 4.6.2,我想用控制台应用程序构建主从结构 在根目录中,我有我的主应用程序。应用程序启动后,将启动位于根目录子目录中的从属程序 ProcessStartInfo startInfo = new ProcessStartInfo("SomeApplication.exe"); startInfo.WorkingDirectory = "C:\SomeOtherDirectory"; Process.Start(startInfo); 到目前为止还没有问题。真正的问题是,所有应用程序都像位于根目录中一样启动

我想用控制台应用程序构建主从结构

在根目录中,我有我的主应用程序。应用程序启动后,将启动位于根目录子目录中的从属程序

ProcessStartInfo startInfo = new ProcessStartInfo("SomeApplication.exe");
startInfo.WorkingDirectory = "C:\SomeOtherDirectory";
Process.Start(startInfo);
到目前为止还没有问题。真正的问题是,所有应用程序都像位于根目录中一样启动。因此,我将从应用程序获取的所有文件都放在根目录中,而从目录中没有任何文件

ProcessStartInfo startInfo = new ProcessStartInfo("SomeApplication.exe");
startInfo.WorkingDirectory = "C:\SomeOtherDirectory";
Process.Start(startInfo);
是否可以像在windows资源管理器中双击一样启动应用程序(最好使用Process类或类似类)?

您可以设置
ProcessStartInfo
的属性来设置基本目录

ProcessStartInfo startInfo = new ProcessStartInfo("SomeApplication.exe");
startInfo.WorkingDirectory = "C:\SomeOtherDirectory";
Process.Start(startInfo);

如果应用程序的编码正确,那么从何处开始流程并不重要。