2

Greetings

I'm using the following code to get the active process.

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public extern short GetKeyState(int keyCode);
[DllImport("user32.dll")]
private extern Int32 GetWindowThreadProcessId(
    IntPtr hWnd, out uint lpdwProcessId);

[DllImport("user32.dll")]
private extern IntPtr GetForegroundWindow();

private Process GetProcessByHandle(IntPtr hwnd)
{
    try
    {
        uint processID;
        GetWindowThreadProcessId(hwnd, out processID);
        return Process.GetProcessById((int)processID);
    }
    catch { return null; }
}

private Process GetActiveProcess()
{
    IntPtr hwnd = GetForegroundWindow();
    return hwnd != null ? GetProcessByHandle(hwnd) : null;
}

I was wondering if with this, or any other code, I could get the active URL / Tab of any webbrowser when GetActiveProcess returns a webbrowser as active process?

Greetings

Theun Arbeider
  • 5,259
  • 11
  • 45
  • 68

1 Answers1

1

Found my answer at Retrieve current URL from C# windows forms application . Which does get the url for google chrome (My most used broswer) but fails at internet explorer.

If anyone wishes to help on that it would be lovely.. but as I have it now it's good enough!

Community
  • 1
  • 1
Theun Arbeider
  • 5,259
  • 11
  • 45
  • 68