1

i have this code for open explorer (by pressing button):

System.Diagnostics.Process.Start("IExplore.exe",@"C:\Help.html");

the problem is, if i press the button more than one time - the explorer will open a lot of shows

how to force the explorer to open only one time ?

thanks

Gali
  • 14,511
  • 28
  • 80
  • 105
  • 1
    have a look at this answer, may point you in the right direction http://stackoverflow.com/questions/187915/detecting-a-process-is-already-running-in-windows-using-c-sharp-net – Jay Oct 16 '12 at 08:09
  • you can disable the button once you have clicked once .. – MMK Oct 16 '12 at 08:09
  • @MMK I was thinking that as well, but what happens if the user closes the browser and wants to re-launch from the OP's app? – Jay Oct 16 '12 at 08:10
  • Why don't you disable the button just after you click on it ? – Jomy John Oct 16 '12 at 08:10
  • 1
    Google it and you can find this: http://social.msdn.microsoft.com/forums/en-US/winforms/thread/745389ab-5745-477b-b698-8097e3fb33b2/ – Simon Wang Oct 16 '12 at 08:10
  • @Jay comment will lead to right direction than – MMK Oct 16 '12 at 08:11

6 Answers6

2
if (Process.GetProcessesByName("iexplore").Length == 0)
    System.Diagnostics.Process.Start("IExplore.exe", @"C:\Help.html");
Danilo Vulović
  • 2,983
  • 20
  • 31
1
  1. Disable button.
  2. Control clicking by a flag

ie ; on_btn_clkd()
{
if(!previouslyClickd)
{
(Click functionalities)
previouslyClicked = false;
}
else
return ;

0

Try to use this piece of code:

bool ProcessIsRunning(string process)
{
    return (System.Diagnostics.Process.GetProcessesByName(process).Length != 0);
}

Usage:

if (!ProcessIsRunning("IExplore.exe"))
    System.Diagnostics.Process.Start("IExplore.exe",@"C:\Help.html");
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
0

You can do like this

private void Form1_Load(object sender, EventArgs e)
    {
        IeProcess = new Process();
        startInfo = new ProcessStartInfo("IExplore.exe");
        startInfo.WindowStyle = ProcessWindowStyle.Maximized;
    }

private void buttonStackoverflow_Click(object sender, EventArgs e)
    {
        startInfo.FileName = "www.Stackoverflow.com";
        IeProcess.StartInfo = startInfo;
        IeProcess.Start();
    }

    private void buttongoogle_Click(object sender, EventArgs e)
    {
        startInfo.FileName = "www.google.com";
        IeProcess.Start();
    }
Neeraj Kumar Gupta
  • 2,157
  • 7
  • 30
  • 58
0

Make use of ShDocVw.dll..
declare in instance of Internet explorer in your class

InternetExplorer wBrowser;

and in your button click add

if (wBrowser==null)
    {
     wBrowser = new InternetExplorer();
     wBrowser.Visible = true;
     wBrowser.Navigate(@"C:\Help.html");
    }

you need to add reference to ShDocVw which you will find in System32 in your project and import namespace using SHDocVw;

techBeginner
  • 3,792
  • 11
  • 43
  • 59
0

If sour default browser is IE just try this code:

System.Diagnostics.Process.Start(@"C:\Help.html");
Ria
  • 10,237
  • 3
  • 33
  • 60