Launch the default web browser, but not if the URL is already open

I have a link to the user interface of an application that launches a URL using System.Diagnostics.Process.Start(). If the user clicks the link several times, he opens several tabs.

Is there a way, possibly a command-line option, to still use the default web browser, but does it just open the same tab again if the URL is already open? It would be nice if it did not work with every possible browser there, but it is nice if it at least works with IE, Firefox and Chrome.

I doubt it, but since I did not see other questions / answers on this topic, I decided that I would ask.

+3
source share
1 answer

, . System.Diagnostics.Process.ProcessId. IE, , . " ", .

WinForm , Google IE, , .

System.Diagnostics.

    public int ProcessID;
    public Form1()
    {
        InitializeComponent();
    }
    private void MyButton_Click(object sender, EventArgs e)
    {
        if (ProcessID == null)
        {
            StartIE();
        }
        else
        {
            if (!ProcessIsRunning())
            {
                StartIE();
            }
        }
    }
    private bool ProcessIsRunning()
    {
        bool ProcessRunning = false;
        foreach (Process p in Process.GetProcesses())
        {
            try
            {
                if (p.Id == ProcessID)
                {
                    ProcessRunning = true;
                }
            }
            catch { }
        }
        return ProcessRunning;
    }
    private void StartIE()
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = "iexplore.exe";
        proc.StartInfo.Arguments = "http://www.google.be";
        proc.Start();
        ProcessID = proc.Id;
    }

, , . , ...

, .

+3

All Articles