Beispiel #1
0
        private ActiveWindow GetActiveWindowInfo()
        {
            var activeWindow = new ActiveWindow();
            IntPtr hWnd = MyUser32.GetForegroundWindow();
            uint procId = 0;
            MyUser32.GetWindowThreadProcessId(hWnd, out procId);

            try
            {
                var proc = Process.GetProcessById((int)procId);
                activeWindow.From = DateTime.Now.ToUniversalTime();
                activeWindow.To = DateTime.Now.ToUniversalTime();
                activeWindow.ProcessName = proc.ProcessName;
                activeWindow.WindowTitle = proc.MainWindowTitle;
                activeWindow.ModuleName = proc.MainModule.ModuleName;
                activeWindow.CompanyName = proc.MainModule.FileVersionInfo.CompanyName;
                activeWindow.Description = proc.MainModule.FileVersionInfo.FileDescription;
                activeWindow.FileName = proc.MainModule.FileVersionInfo.FileName;
                activeWindow.ProductName = proc.MainModule.FileVersionInfo.ProductName;
            }
            catch (Win32Exception e)
            {
                Debug.WriteLine("Win32 exception: " + e.Message);
            }

            activeWindow.Url = DataCollectorBrowser.GetBrowserUrl(activeWindow, hWnd);
            if (activeWindow.Url != null && activeWindow.Url != "")
            {
                Debug.WriteLine(activeWindow.Url);
            }

            return activeWindow;
        }
        public static string GetBrowserUrl(ActiveWindow window, IntPtr hWnd)
        {
            string url = null;
            try
            {
                // Microsoft Edge
                if (window.ProcessName.Equals("ApplicationFrameHost") &&
                    (window.WindowTitle.EndsWith("- Microsoft Edge") ||
                    window.WindowTitle.EndsWith("- [InPrivate] - Microsoft Edge")))
                {
                    url = GetBrowserEdgeUrl(hWnd);
                }

                // Internet Explorer IE 8-11
                if (window.ProcessName.Equals("iexplore") &&
                    (window.WindowTitle.EndsWith("- Internet Explorer") ||
                    window.WindowTitle.EndsWith("- Internet Explorer - [InPrivate]") ||
                    window.WindowTitle.EndsWith("- Windows Internet Explorer") ||
                    window.WindowTitle.EndsWith("- Windows Internet Explorer - [InPrivate]") ||
                    window.WindowTitle.EndsWith("- [InPrivate]")))
                {
                    url = GetBrowserIEUrl(hWnd);
                }

                // Google Chrome 46
                if (window.ProcessName.Equals("chrome") && window.WindowTitle.EndsWith("- Google Chrome"))
                {
                    url = GetBrowserChromeUrl(hWnd);
                }

                // Yandex 15.10
                if (window.ProcessName.Equals("browser") && window.WindowTitle.EndsWith("– Yandex"))
                {
                    url = GetBrowserYandexUrl(hWnd);
                }

                // Opera 33
                if (window.ProcessName.Equals("opera") && window.WindowTitle.EndsWith("— Opera"))
                {
                    url = GetBrowserOperaUrl(hWnd);
                }

                // Mozilla Firefox 42
                // Mozilla Developer Edition 45
                // Tor Browser 5
                if ((window.ProcessName.Equals("firefox") &&
                        (window.WindowTitle.EndsWith("- Mozilla Firefox") ||
                        window.WindowTitle.EndsWith("- Mozilla Firefox (Приватный просмотр)"))) ||
                    (window.ProcessName.Equals("firefox") &&
                        (window.WindowTitle.EndsWith("- Firefox Developer Edition") ||
                        window.WindowTitle.EndsWith("- Firefox Developer Edition (Приватный просмотр)"))) ||
                    (window.ProcessName.Equals("firefox") && window.WindowTitle.EndsWith("- Tor Browser")))
                {
                    url = GetBrowserFirefoxUrl(hWnd);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("UI Automation exception: " + e.ToString());
                url = null;
            }

            return url;
        }
Beispiel #3
0
 private bool IsEqualWindowInfo(ActiveWindow a, ActiveWindow b)
 {
     if (a.ProcessName != b.ProcessName) return false;
     if (a.ModuleName != b.ModuleName) return false;
     if (a.WindowTitle != b.WindowTitle) return false;
     if (a.CompanyName != b.CompanyName) return false;
     if (a.Description != b.Description) return false;
     if (a.FileName != b.FileName) return false;
     if (a.ProductName != b.ProductName) return false;
     if (a.Url != b.Url) return false;
     return true;
 }