Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 223911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:16:00+00:00 2026-05-11T19:16:00+00:00

From a C# application I want to activate (brint to front) a site that

  • 0

From a C# application I want to activate (brint to front) a site that is already open in the users default browser. I want to do this in a browser agnostic way.

The difficult part (for me at least) is that I do not want the browser to open a new tab and the browser must not reload the page if it is already open.

I can open the URI in the default browser with

System.Diagnostics.Process.Start("http://foo.example");

But the exact behaviour depends on the users default browser (IE6 seems to reuse the current topmost browser window, Google Chrome will always open a new tab and so on)

Another approach I tried was to enumerate all open Windows and find the one I want based on the window title (making the assumption that most browsers set the window title to the title of the currently open page)

public delegate bool EnumThreadWindowsCallback(int hWnd, int lParam);

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);

[DllImport("user32.dll")]
static extern int GetWindowText(int hWnd, StringBuilder text, int count);

private bool FindWindowByRx(int hWnd, int lParam)
{
    Regex pattern = new Regex("Example Title of Page", RegexOptions.IgnoreCase);
    StringBuilder windowTitle = new StringBuilder(256);
    GetWindowText(hWnd, windowTitle, 255);

    if (pattern.IsMatch(windowTitle.ToString()))
    {
        SetForegroundWindow(new IntPtr(hWnd));
        return false; // abort search
    }
    else
    {
        return true; // keep on searching
    }
}

using it with:

EnumWindows(new EnumThreadWindowsCallback(FindWindowByRx), new IntPtr());

This does what I need it to do, but feels very brittle and hackish, and is probably slow.

Is there a better, more elegant way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:16:00+00:00Added an answer on May 11, 2026 at 7:16 pm

    This will work, IF the user has that site active in their browser. If they’re using a tabbed browser, and the site is open, but not in the selected tab, I don’t believe you will ever find the browser window. (EnumWindows only enumerates top-level windows).

    If the user’s started a new tab, you’ll end up not finding it, and (likely) starting a second copy of the site in a new tab.

    Personally, if you really need to restrict to a single browser instance, I would consider whether its possible to embed the browser in your application instead of using the default browser. If this can be made a GUI element in your application using a browser control, you’d have much more control and be able to avoid this type of workaround.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want copy pdf file from application path(/data/data/package name) to sdcard.for that i have
In my application I want to call service from Receiver. This is my NotificationReceiver.java
I want to use Custom URL Scheme to transfer data from application to other
Hi I want to send message from one application (which will be installed on
I want to launch from my application the activity recent apps, without holding on
I want to prevent my application from being reverse engineered and decompiled by someone
In my application i want to select the video from library by using UIImagePickerController.
I want to run another Application (Polaris Office) directly from my Application. But it
I want to send notification from PHP application and same time it should be
In my application I want to upload file from SD card to my server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.