Exemplo n.º 1
0
        public static Process GetBrowserProcess(Func <IntPtr> getBrowserWindow, string processName)
        {
            Process processById;

            try
            {
                do
                {
                    uint   processId;
                    IntPtr browserWindow;
                    do
                    {
                        browserWindow = getBrowserWindow.Invoke();
                        processId     = 0;
                        if (browserWindow != IntPtr.Zero)
                        {
                            Win32Interop.GetWindowThreadProcessId(browserWindow, out processId);
                        }
                    } while (processId == 0);
                    Win32Interop.GetWindowThreadProcessId(browserWindow, out processId);
                    processById = Process.GetProcessById(unchecked ((int)processId));
                } while (processById.HasExited);
                processById.EnableRaisingEvents = true;
            }
            catch
            {
                var processesByName = Process.GetProcessesByName(processName);
                foreach (var processbyname in processesByName)
                {
                    if (!processbyname.HasExited)
                    {
                        processbyname.Kill();
                    }
                }
                return(null);
            }
            return(processById);
        }
Exemplo n.º 2
0
        public WindowHookNet HookFirefoxCreation(ByRef <Process> ffProcessId,
                                                 EventHandler <WindowHookEventArgs> firefowWindowCreated = null)
        {
            void WindowHookNetWindowCreated(object aSender, WindowHookEventArgs aArgs)
            {
                Debug.WriteLine($"{aArgs.WindowClass}-{aArgs.WindowTitle}");
                foreach (var windowclass in _windowclass)
                {
                    if (aArgs.WindowClass == windowclass)
                    {
                        uint processId;
                        Win32Interop.GetWindowThreadProcessId(aArgs.Handle, out processId);
                        if (EvaluateCondition(ffProcessId, processId))
                        {
                            FirefowWindowCreated?.Invoke(this, aArgs);
                            firefowWindowCreated?.Invoke(this, aArgs);
                        }
                    }
                }
            }

            return(GetWindowHookNet(WindowHookNetWindowCreated));
        }
Exemplo n.º 3
0
        private static Thread FindBrowserWindow(Action <IntPtr> setChromeWindow,
                                                Tuple <Func <IEnumerable <IntPtr> >, string> tuple)
        {
            void Start(object param)
            {
                var     tupleFromParam = (Tuple <Func <IEnumerable <IntPtr> >, string>)param;
                var     findWindows    = tupleFromParam.Item1;
                var     title          = tupleFromParam.Item2;
                Process processById;
                IntPtr  window;

                do
                {
                    uint processId;
                    do
                    {
                        var windowTitles = findWindows.Invoke()
                                           .FindWindowByTitle(title)
                                           .ToArray();
                        window = windowTitles.FirstOrDefault();
                        Win32Interop.ShowWindowAsync(window, ShowInfo.Minimize);
                        Win32Interop.GetWindowThreadProcessId(window, out processId);
                    } while (processId == 0);
                    Win32Interop.GetWindowThreadProcessId(window, out processId);
                    processById = Process.GetProcessById(unchecked ((int)processId));
                } while (processById.HasExited);
                Win32Interop.ShowWindowAsync(window, ShowInfo.ShowMinimized);
                setChromeWindow(window);
            }

            Thread thread = new Thread(Start);

            thread.Priority = ThreadPriority.AboveNormal;
            thread
            .Start(tuple);
            return(thread);
        }