简体   繁体   中英

Run .exe with C# Form

I currently have the following set up:

namespace TSRVTC_GUI
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void btnselect_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog fdb = new FolderBrowserDialog();
        if (fdb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            txtpath.Text = fdb.SelectedPath;
    }

    private void btnlaunch_Click(object sender, EventArgs e)
    {
        Process.Start(@"fdb\Launcher.exe");
    }
}

}

I am trying to start a program contained within a different directory to the .exe but this doesn't work, if someone could help me I'd appreciate it.

I also apologize for the back structure of this question but I am still new on here.

You can use Text property of txtpath instance of TextBox as you are setting the Path in it from FolderBrowseDialog instance, you can do it like:

Process.Start(txtpath.Text);

and if the path is without executable name then you will have to write like:

Process.Start(txtpath.Text+"\launcher.exe");

or more better is to use Path.Combine :

Process.Start(Path.Combine(txtpath.Text,"launcher.exe"));

and for able to use Path class, you would need to add using System.IO in the usings of your class.

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM