开发者

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

开发者 https://www.devze.com 2023-01-02 01:01 出处:网络
I\'m trying to start an application programatically, but it always runs it in the folder of my application... For example:

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.StartInf开发者_开发问答o.FileName = application.FileName;
    process.StartInfo.Arguments = application.AppName;
    process.Start();
}


I guess you mean ProcessStartInfo.WorkingDirectory Property


Use process.StartInfo.WorkingDirectory = pathToTheFolder;.


Just set the WorkDirectory property.

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

精彩评论

暂无评论...
验证码 换一张
取 消