Search code examples
c#executableconfirmation

Run executable and show confirmation using C#?


I am doing some C# code and I want to run an .exe when pressing an image. Its working fine this way:

private void pictureBox1_Click(object sender, EventArgs e)
{
    Process.Start("C:\\something.exe");
}

But, how can I add a message that when you click on the image, a box appears asking if you really want to run the .exe?

It would be great if someone could help me. Thanks.


Solution

  • You could use simple MessageBox

    private void pictureBox1_Click(object sender, EventArgs e)
        {
           if(MessageBox.Show("Are you really sure you want to run the program?", "Notification", MessageBoxButtons.OKCancel) == DialogResult.OK)
             Process.Start("C:\\something.exe");
        }