Created
May 19, 2020 17:11
-
-
Save drawcode/dc9c4e053e6d35e97f186ea2c6d91876 to your computer and use it in GitHub Desktop.
App/Url Tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetChromeUrl(Process process) | |
{ | |
if (process == null) | |
throw new ArgumentNullException("process"); | |
if (process.MainWindowHandle == IntPtr.Zero) | |
return null; | |
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle); | |
if (element == null) | |
return null; | |
AutomationElement edit = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); | |
return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; | |
} | |
public static string GetInternetExplorerUrl(Process process) | |
{ | |
if (process == null) | |
throw new ArgumentNullException("process"); | |
if (process.MainWindowHandle == IntPtr.Zero) | |
return null; | |
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle); | |
if (element == null) | |
return null; | |
AutomationElement rebar = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32")); | |
if (rebar == null) | |
return null; | |
AutomationElement edit = rebar.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); | |
return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; | |
} | |
public static string GetFirefoxUrl(Process process) | |
{ | |
if (process == null) | |
throw new ArgumentNullException("process"); | |
if (process.MainWindowHandle == IntPtr.Zero) | |
return null; | |
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle); | |
if (element == null) | |
return null; | |
AutomationElement doc = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)); | |
if (doc == null) | |
return null; | |
return ((ValuePattern)doc.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; | |
} | |
static void Main(string[] args) | |
{ | |
foreach (Process process in Process.GetProcessesByName("firefox")) | |
{ | |
string url = GetFirefoxUrl(process); | |
if (url == null) | |
continue; | |
Console.WriteLine("FF Url for '" + process.MainWindowTitle + "' is " + url); | |
} | |
foreach (Process process in Process.GetProcessesByName("iexplore")) | |
{ | |
string url = GetInternetExplorerUrl(process); | |
if (url == null) | |
continue; | |
Console.WriteLine("IE Url for '" + process.MainWindowTitle + "' is " + url); | |
} | |
foreach (Process process in Process.GetProcessesByName("chrome")) | |
{ | |
string url = GetChromeUrl(process); | |
if (url == null) | |
continue; | |
Console.WriteLine("CH Url for '" + process.MainWindowTitle + "' is " + url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment