how to

  • Thread starter Thread starter Max3vil
  • Start date Start date
M

Max3vil

I would like to write an application with 2 button. For each button i would
like to lounch an other application, and it verify if it is already run.
Any ideas ?

tnx
 
Hi Max3vil,

A simple solution would be something like this

private void button1_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("notepad");

if (processes.Length > 0)
MessageBox.Show("Notepad already started");
else
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("notepad.exe");
p.Start();
}
}

This is not very robust though. If another program would call itself
notepad the code above will fail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top