从我的C#程序的同一文件夹中启动.exe

Joa*_*oao 3 c# wpf

我在c#中创建了一个小程序,其中一个按钮可以打开另一个.exe文件.

如果我使用它,它工作正常:

private void start_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"path to file");
        }
Run Code Online (Sandbox Code Playgroud)

但是如果我想让它从同一个文件夹运行.exe,我基本上想要这样的东西:

private void start_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"program.exe");
        }
Run Code Online (Sandbox Code Playgroud)

我错过了什么,我尝试过这个网站的解决方案:

var startIngo = new ProcessStartInfo();
startIngo.WorkingDirectory = // working directory
// set additional properties 

Process proc = Process.Start(startIngo);
Run Code Online (Sandbox Code Playgroud)

但Visual c#根本不识别"ProcessStartInfo"......

Ice*_*ind 11

你在寻找的是:

Application.StartupPath
Run Code Online (Sandbox Code Playgroud)

它将返回启动可执行文件的启动路径.

如果您使用的是WPF,请尝试以下方法:

String appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
Run Code Online (Sandbox Code Playgroud)