Hi,
I'm fighting to understand how to add code found on the internet correctly into a new project.
Let me give u an example here. If i Add some code i found on the internet it gives a lot of errors. The fist error is : The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?)
Am I inserting the code in the wrong place. Please advice.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
-
-
-
-
-
-
- Process[] procsChrome = Process.GetProcessesByName("chrome");
- foreach (Process chrome in procsChrome)
- {
-
- if (chrome.MainWindowHandle == IntPtr.Zero)
- {
- continue;
- }
-
-
- AutomationElement elm = AutomationElement.FromHandle(chrome.MainWindowHandle);
-
-
- AutomationElement elmUrlBar = null;
- try
- {
-
- var elm1 = elm.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Google Chrome"));
- if (elm1 == null) { continue; }
-
-
- var elm2 = TreeWalker.RawViewWalker.GetLastChild(elm1);
- var elm3 = elm2.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, ""));
- var elm4 = elm3.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar));
- elmUrlBar = elm4.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
- }
- catch
- {
-
-
- continue;
- }
-
-
- if (elmUrlBar == null)
- {
-
- continue;
- }
-
-
- if ((bool)elmUrlBar.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty))
- {
- continue;
- }
-
-
- AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
- if (patterns.Length == 1)
- {
- string ret = "";
- try
- {
- ret = ((ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0])).Current.Value;
- }
- catch { }
- if (ret != "")
- {
-
- if (Regex.IsMatch(ret, @"^(https:\/\/)?[a-zA-Z0-9\-\.]+(\.[a-zA-Z]{2,4}).*$"))
- {
-
- if (!ret.StartsWith("http"))
- {
- ret = "http://" + ret;
- }
- Console.WriteLine("Open Chrome URL found: '" + ret + "'");
- }
- }
- continue;
- }
- }
-
-
-
-
- }
- }
- }
Thank you in advanced for all your replies!