Skip to content

C# help please

Marco Blandon

Asked Dec 20, 2008, 11:08 AM EST3 answers
Share
LinkedInX
Hello, I'm just starting with C# and I have a little problem. I want to create a form that asks you for an exe file (you type the path) and when you click launch it will open the exe file. Here is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

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

        private void button1_Click(object sender, EventArgs e)
        {
            Process process = new Process();
            string path = Convert.ToString(textBox1);
            process.StartInfo.FileName = path;
            process.Start();


            string name = Convert.ToString(textBox2);
            string pass = Convert.ToString(textBox3);
            string ip = Convert.ToString(textBox4);
        }
    }
}

The error is a Win32Exception. Cannot find the path specified. I tried running notepad typing the whole path, only the exe file, with " "between the path but nothing works. The only way it works is if you type the path of the exe in the code.
Thank you.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    To open any exe you can write this single line of code

    System.Diagnostic.Process.Start(@"....your path here....");
    0
  • 0
    Thank you for the reply. Problem was the Convert.ToString(textBox1) I need to add textBox1.Text.
    0
  • 1 short reply
    • Bechir Bejaoui
      0
      I see
      0