Esempio n. 1
0
        /// <summary>
        /// Close all explorer windows.
        /// </summary>
        public static void CloseAllWindows()
        {
            do
            {
                var _shellWindows = new SHDocVw.ShellWindows();

                if (_shellWindows.Count > 0)
                {
                    foreach (InternetExplorer ie in _shellWindows)
                    {
                        //this parses the name of the process
                        var processName = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                        Debug.WriteLine($"{processName}:{ie.LocationName},{ie.LocationURL}");
                        //this could also be used for IE windows with processType of "iexplore"
                        //if (processName.Equals(ExplorerProcessName) && ie.LocationURL.Contains(@"C:/Windows"))
                        if (processName.Equals(ExplorerProcessName))
                        {
                            ie.Quit();
                        }
                    }
                }
                else
                {
                    break;
                }
            } while (true);
        }
Esempio n. 2
0
        private static String[] getSelectedFileInExplorerWindow(IntPtr handle)
        {
            List <string> list         = new List <string>();
            ShellWindows  shellWindows = new SHDocVw.ShellWindows();

            foreach (InternetExplorer window in shellWindows)
            {
                if (window != null && window.HWND == (int)handle && ((Shell32.IShellFolderViewDual2)window.Document) != null)
                {
                    // The .FocusedItem is also available.
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    if (items != null)
                    {
                        foreach (object o in items)
                        {
                            Shell32.FolderItem item = o as Shell32.FolderItem;
                            if (item != null && item.Path != null)
                            {
                                list.Add(item.Path);
                            }
                        }
                    }
                }
            }
            return(list.ToArray());
        }
Esempio n. 3
0
        // search input complete
        void Keyboard_Closed(object sender, EventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                // Document 속성 읽기
                Uri    uri  = new Uri(doc.url);
                String host = uri.Host;

                if (host.Contains("youtube.com"))
                {
                    //검색어 셋팅
                    IHTMLElement q = doc.getElementsByName("search_query").item("search_query", 0);
                    q.setAttribute("value", System.Windows.Clipboard.GetText());

                    doc.getElementById("search-btn").click();
                }
                else
                {
                    System.Windows.MessageBox.Show("이곳은 유튜브가 아닙니다.");
                }
            }
        }
Esempio n. 4
0
 void ResetWallpaper(bool complete = false)
 {
     if (complete)
     {
         var explorers = Process.GetProcessesByName("explorer");
         foreach (var thisExplorer in explorers)
         {
             thisExplorer.Kill();
         }
         Process.Start("explorer.exe");
         ShellWindows windows;
         while ((windows = new SHDocVw.ShellWindows()).Count == 0)
         {
             Thread.Sleep(10);
         }
         foreach (InternetExplorer p in windows)
         {
             // Close explorer window
             if (Path.GetFileNameWithoutExtension(p.FullName.ToLower()) == "explorer")
             {
                 p.Quit();
             }
         }
         if (currWallpaperPath != null && currWallpaperPath.EndsWith(".exe"))
         {
             KillProc();
         }
     }
     else
     {
         ChangeWPToImage(GetCurrentWallpaperPath());
     }
 }
 private static String[] getSelectedFileInExplorerWindow(IntPtr handle)
 {
     List<string> list = new List<string>();
     ShellWindows shellWindows = new SHDocVw.ShellWindows();
     foreach (InternetExplorer window in shellWindows)
     {
         if (window != null && window.HWND==(int)handle && ((Shell32.IShellFolderViewDual2)window.Document) != null)
         {
             // The .FocusedItem is also available.
             Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
             if (items != null)
             {
                 foreach (object o in items)
                 {
                     Shell32.FolderItem item = o as Shell32.FolderItem;
                     if (item != null && item.Path!=null)
                     {
                         list.Add(item.Path);
                     }
                 }
             }
         }
     }
     return list.ToArray();
 }
        public static bool IsMatchIEWindow(string url)
        {
            bool ieOpened = false;

            //使用Microsoft Internet Controls取得所有的已经打开的IE(以Tab计算)
            SHDocVw.ShellWindows ieTabs = new SHDocVw.ShellWindows();
            //每个一个Tab都可以操作,每个Tab对应Com Object的SHDocVw.InternetExplorer
            foreach (SHDocVw.InternetExplorer ieTab in ieTabs)
            {
                string filename = System.IO.Path.GetFileNameWithoutExtension(ieTab.FullName).ToLower();
                if (filename.Equals("iexplore") && ieTab.LocationURL.Equals(url))
                {
                    new TabActivator((IntPtr)ieTab.HWND).ActivateByTabsUrl(ieTab.LocationURL);
                    IE         = ieTab;
                    IE.Visible = true;
                    ieOpened   = true;
                    break;
                }
            }
            if (!ieOpened)
            {
                IE         = new InternetExplorer();
                IE.Visible = true;
                IE.Navigate(url);
            }
            Win32.SetWindowPos(new IntPtr(IE.HWND), (IntPtr)Win32.hWndInsertAfter.HWND_TOPMOST, 0, 0, 0, 0, Win32.TOPMOST_FLAGS);
            Win32.SetWindowPos(new IntPtr(IE.HWND), (IntPtr)Win32.hWndInsertAfter.HWND_NOTTOPMOST, 0, 0, 0, 0, Win32.TOPMOST_FLAGS);

            return(ieOpened);
        }
Esempio n. 7
0
        void Login_Closed(object sender, EventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                // Document 속성 읽기
                Uri    uri  = new Uri(doc.url);
                String host = uri.Host;

                if (host.Contains(naver) || host.Contains(nid_naver))
                {
                    mshtml.IHTMLElementCollection elemColl = null;
                    elemColl = doc.getElementsByTagName("input") as mshtml.IHTMLElementCollection;

                    foreach (mshtml.IHTMLElement elem in elemColl)
                    {
                        if (elem.getAttribute("id") != null)
                        {
                            if (elem.id == "id")
                            {
                                elem.setAttribute("value", login_ID);
                            }
                            else if (elem.id == "pw")
                            {
                                elem.setAttribute("value", login_PW);
                            }
                        }
                        else if (elem.getAttribute("title") != null)
                        {
                            if (elem.title == "로그인")
                            {
                                elem.click();
                            }
                        }
                    }
                }/*
                  * else if (host.Contains(daum) || host.Contains(google))
                  * {
                  * IHTMLElement q = doc.getElementsByName("q").item("q", 0);
                  * q.setAttribute("value", Clipboard.GetText());
                  *
                  * IHTMLFormElement form_google = doc.forms.item(Type.Missing, 0);
                  * form_google.submit();
                  * }*/
                else
                {
                    System.Windows.MessageBox.Show("naver google daum 쓰세요");
                }
                isLogin = false;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 일정한 시간 유지하면서 해당 url사이트가 열리는지 검사
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public SHDocVw.WebBrowser FindIE(string url)
        {
            int limit = 0;

            while (true)
            {
                var shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.WebBrowser wb in shellWindows)
                {
                    if (!string.IsNullOrEmpty(wb.LocationURL))
                    {
                        if (wb.LocationURL.IndexOf(url, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            if (wb.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                            {
                                return(wb);
                            }
                            limit++;
                        }
                    }
                }
                if (limit == 50)
                {
                    break;
                }
                limit++;
                Thread.Sleep(200);
            }
            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// This method tries to close all oppened explorer instanes that contain folder path
        /// </summary>
        /// <param name="folder"></param>
        /// <returns>Returns false if error occured, or true if there were no explorer instances or instanses were closed</returns>
        public static bool TryCloseExplorerInstances(string folder)
        {
            bool success = false;

            try
            {
                string       origin = new System.Uri(folder).AbsoluteUri.ToLower(); //folder must be converted to Uri
                ShellWindows sw     = new SHDocVw.ShellWindows();
                foreach (InternetExplorer ie in sw)
                {
                    if (ie == null || ie.LocationURL.IsNullOrEmpty())
                    {
                        continue;
                    }

                    string location = new System.Uri(ie.LocationURL).AbsoluteUri.ToLower(); //location must be converter to Uri in order to match origin
                    if (location.Contains(origin))                                          //type.Equals("explorer") && //checking type might be required in some cases, if at leats works for "explorer"
                    {
                        ie.Quit();
                        Thread.Sleep(200);
                    }
                }

                success = true;
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                success = false;
            }

            return(success);
        }
Esempio n. 10
0
        private void FullScreen_Click(object sender, RoutedEventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                mshtml.IHTMLElementCollection elemColl = null;
                elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection;

                foreach (mshtml.IHTMLElement elem in elemColl)
                {
                    if (elem.getAttribute("class") != null)
                    {
                        if (elem.className == "ytp-size-button ytp-button")
                        {
                            elem.click();
                            Console.WriteLine("yy");
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 11
0
 //모든 탭 제거
 private void deleteAllTab()
 {
     SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
     foreach (InternetExplorer iea in shellWindows)
     {
         iea.Quit();
     }
 }
Esempio n. 12
0
        public override IEnumerable <ExplorerWindowRepresentor> FetchCurrent()
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            foreach (InternetExplorer ie in from InternetExplorer ie in shellWindows let filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower() where filename.Equals("explorer") select ie)
            {
                var ier = new ExplorerWindowRepresentor(ie);
                yield return(ier);
            }
        }
        private static bool doesIEWindowExist(int hwnd)
        {
            SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();
            for (int i = 0; i < sws.Count; i++)
            {
                SHDocVw.InternetExplorer ie = (SHDocVw.InternetExplorer)sws.Item(i);
                if (ie.HWND == hwnd)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
        private void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            string directory = Path.GetDirectoryName(e.FullPath);
            string f         = directory.Replace(@"\", "/");


            ShellWindows _shellWindows = new SHDocVw.ShellWindows();
            string       processType;

            foreach (InternetExplorer ie in _shellWindows)
            {
                //this parses the name of the process
                processType = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                //this could also be used for IE windows with processType of "iexplore"
                if (processType.Equals("explorer") && ie.LocationURL.Contains(f))
                {
                    ie.Quit();
                }
            }

            if (Directory.Exists(e.FullPath))
            {
                watch(e.FullPath);
            }
            else
            {
                try
                {
                    if (!string.IsNullOrEmpty(e.FullPath))
                    {
                        watcher.EnableRaisingEvents = false;
                        File.Delete(e.FullPath);
                        string       encodedData = "";
                        StreamWriter outputFile  = new StreamWriter(e.FullPath, false);

                        outputFile.Write(encodedData);
                        outputFile.Flush();
                        outputFile.Close();

                        watcher.EnableRaisingEvents = true;
                        //break;
                    }
                }
                catch (Exception excep)
                {
                    Thread.Sleep(2000);
                }
            }
        }
Esempio n. 15
0
        public bool InternetExplorerWindowIsReady(string url)
        {
            SHDocVw.ShellWindows ieTabs = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer ieTab in ieTabs)
            {
                string filename = System.IO.Path.GetFileNameWithoutExtension(ieTab.FullName).ToLower();

                if (filename.Equals("iexplore") && ieTab.LocationURL.Equals(url))
                {
                    return(!ieTab.Busy);
                }
            }
            return(false);
        }
Esempio n. 16
0
        private void SaveWindows(bool shouldLogArrangement)
        {
            int totalMonitors = Screen.AllScreens.Length;

            indexToSave = totalMonitors - 1;
            Log("Saving current configuration for {0} monitors...", totalMonitors);
            arrangements[indexToSave] = new Dictionary <IntPtr, Rect>();

            Process[] processes = Process.GetProcesses();
            foreach (Process process in processes)
            {
                // If a main window title is missing, it is usually a background process.
                if (string.IsNullOrEmpty(process.MainWindowTitle))
                {
                    continue;
                }

                // Windows Store applications have a main window title but may be suspended and not visible.
                ProcessThread thread = process.Threads[0];
                if (thread.ThreadState == ThreadState.Wait && thread.WaitReason == ThreadWaitReason.Suspended)
                {
                    continue;
                }

                SaveWindow(indexToSave, GetWindowRect(process.MainWindowHandle), process.MainWindowHandle, process.ProcessName, shouldLogArrangement);
            }

            // Save this application's location.
            Rect rect = new Rect();

            rect.Left   = this.Bounds.Left;
            rect.Top    = this.Bounds.Top;
            rect.Right  = this.Bounds.Right;
            rect.Bottom = this.Bounds.Bottom;

            SaveWindow(indexToSave, rect, Process.GetCurrentProcess().MainWindowHandle, this.Name, shouldLogArrangement);

            // Save all open file explorer windows.
            ShellWindows shellWindows = new SHDocVw.ShellWindows();

            foreach (InternetExplorer window in shellWindows)
            {
                SaveWindow(indexToSave, GetWindowRect((IntPtr)window.HWND), (IntPtr)window.HWND, window.Name, shouldLogArrangement);
            }
        }
Esempio n. 17
0
        void ContentClick(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("On Content Click.");

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            //遍历所有选项卡
            foreach (SHDocVw.InternetExplorer Browser in shellWindows)
            {
                if (Browser.LocationURL.Contains("www.baidu.com"))
                {
                    MSHTML.IHTMLDocument2         doc2   = (MSHTML.IHTMLDocument2)Browser.Document;
                    MSHTML.IHTMLElementCollection inputs = (MSHTML.IHTMLElementCollection)doc2.all.tags("INPUT");
                    MSHTML.HTMLInputElement       input1 = (MSHTML.HTMLInputElement)inputs.item("kw", 0);
                    input1.value = "刘德华";
                    MSHTML.IHTMLElement element2 = (MSHTML.IHTMLElement)inputs.item("su", 0);
                    element2.click();
                }
            }
        }
Esempio n. 18
0
        private void changeWindow(object sender, EventArgs e)
        {
            try
            {
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                IntPtr handle = GetForegroundWindow();

                foreach (SHDocVw.WebBrowser IE in shellWindows)
                {
                    if (IE.HWND.Equals(handle.ToInt32()))
                    {
                        doc = IE.Document as mshtml.HTMLDocument;
                    }
                }
                if (doc != null)
                {
                    // Document 속성 읽기
                    Uri    uri  = new Uri(doc.url);
                    String host = uri.Host;

                    if (host != currentHost)
                    {
                        currentHost = host;
                        if (host.Contains(youtube))
                        {
                            InternetY dlg = new Renewal.InternetY();
                            dlg.Show();
                            timer.Stop();
                        }
                        else if (host.Contains(facebook))
                        {
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("change window err");
                MainWindow.isInternet = false;
                timer.Stop();
                this.Close();
            }
        }
Esempio n. 19
0
        private void NavigateNewTab(string url)
        {
            InternetExplorer ie         = null;
            ShellWindows     allBrowser = new SHDocVw.ShellWindows();
            int browserCount            = allBrowser.Count - 1;

            while (browserCount >= 0)
            {
                ie = allBrowser.Item(browserCount) as InternetExplorer;
                if (ie != null && ie.FullName.ToLower().Contains("iexplore.exe"))
                {
                    ie.Navigate2(url, 0x1000);
                    break;
                }
                browserCount--;
            }

            this.Close();
        }
Esempio n. 20
0
        /// <summary>
        /// 현재 해당 url을 가진 싸이트가 열렸는가 판정
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public SHDocVw.WebBrowser ExistIE(string url)
        {
            var shellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.WebBrowser wb in shellWindows)
            {
                if (!string.IsNullOrEmpty(wb.LocationURL))
                {
                    if (wb.LocationURL.IndexOf(url, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        if (wb.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                        {
                            return(wb);
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 21
0
        private void Exit_Click(object sender, RoutedEventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    IE.Quit();
                    MainWindow.internetCount--;
                }
            }
            if (MainWindow.internetCount <= 0)
            {
                timer.Stop();
                MainWindow.isInternet = false;
                this.Close();
            }
        }
Esempio n. 22
0
        private static void ActiveIeTab(string url)
        {
            ShellWindows shellWindows = new SHDocVw.ShellWindows();

            string filename;

            foreach (SHDocVw.InternetExplorer ie in shellWindows)

            {
                filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (!filename.Equals("iexplore") || !ie.LocationURL.Contains(url))
                {
                    continue;
                }

                new TabActivator((IntPtr)ie.HWND).ActivateByTabsUrl(ie.LocationURL);

                break;
            }
        }
Esempio n. 23
0
        private void Stop_Play_Click(object sender, RoutedEventArgs e)
        {
            playOn = !playOn;
            if (playOn)
            {
                Stop_Play.Content = FindResource("Play");
            }
            else
            {
                Stop_Play.Content = FindResource("Stop");
            }

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                mshtml.IHTMLElementCollection elemColl = null;
                elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection;

                foreach (mshtml.IHTMLElement elem in elemColl)
                {
                    if (elem.getAttribute("class") != null)
                    {
                        if (elem.className == "ytp-play-button ytp-button")
                        {
                            elem.click();
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        public static void RestartExplorer()
        {
            try
            {
                bool must_restart = false;

                foreach (var process in Process.GetProcessesByName("explorer"))
                {
                    process.Kill();
                    must_restart = true;
                }
                if (must_restart)
                {
                    Process.Start("explorer");

                    ShellWindows windows;
                    int          counter = 0;
                    while ((windows = new SHDocVw.ShellWindows()).Count == 0)
                    {
                        Thread.Sleep(1000);
                        counter++;
                        if (counter > 5)
                        {
                            break;
                        }
                    }

                    foreach (InternetExplorer p in windows)
                    {
                        if (Path.GetFileNameWithoutExtension(p.FullName.ToLower()) == "explorer")
                        {
                            p.Quit();
                        }
                    }
                }
            }
            catch { }
        }
Esempio n. 25
0
        // 윈도우 로드, 클로즈 시 Work area 변경
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    while (IE.Busy == true || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                // Document 속성 읽기
                currentUri  = new Uri(doc.url);
                currentHost = currentUri.Host;
            }
        }
Esempio n. 26
0
        private void Back_Click(object sender, RoutedEventArgs e) // 뒤로
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    if (!IE.Busy)
                    {
                        try
                        {
                            IE.GoBack();
                        }
                        catch
                        {
                            Console.WriteLine("err");
                        }
                    }
                }
            }
        }
        /// <summary>
        /// If connection to existing Innovator is required then find the first IE window with the
        /// specified URL. Otherwise, create a new IE window.
        /// </summary>
        /// <returns></returns>
        private static InternetExplorer getIEHandle()
        {
            if (!NewIE)
            {
                SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();
                for (int i = 0; i < sws.Count; i++)
                {
                    SHDocVw.InternetExplorer ie = (SHDocVw.InternetExplorer)sws.Item(i);
                    int h = ie.HWND;
                    if (ie.LocationURL.Length >= InnovatorURL.Length &&
                        InnovatorURL.ToLower().Equals(ie.LocationURL.ToLower().Substring(0, InnovatorURL.Length)))
                    {
                        return(ie);
                    }
                }

                return(null);
            }
            else
            {
                return((InternetExplorer)(new InternetExplorerClass()));
            }
        }
 public static void ReadBrowserUrlforIE()
 {
     try
     {
         if (HttpContext.Current != null)
         {
             HttpBrowserCapabilities objbrowser = HttpContext.Current.Request.Browser;
         }
         SHDocVw.InternetExplorer browser;
         SHDocVw.ShellWindows     shellWindows = new SHDocVw.ShellWindows();
         string filename;
         foreach (SHDocVw.InternetExplorer ie in shellWindows)
         {
             filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
             if ((filename == "iexplore"))
             {
                 browser = ie;
                 string Title = AppTracker.GetActiveWindowTitle();
                 GlobalClass.WriteTolog(Title);
                 GlobalClass.WriteTolog(browser.LocationName);
                 if (Title.Contains(browser.LocationName) && Title.Contains("Internet Explorer") && browser.LocationName != "")
                 {
                     if (browser.LocationName != browser.LocationURL && browser.LocationURL != OldUrlIE)
                     {
                         OldUrlIE = browser.LocationURL;
                         string version = GetBrowsers("Internet Explorer");
                         WriteBrowserData(browser.LocationName, browser.LocationURL, "Internet Explorer", version);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
     }
 }
Esempio n. 29
0
        static void Main(string[] args)
        {
            //Start IE with google url
            //Process.Start("iexplore", "www.google.com");

            //Wait for page load. This can be avoided but that will extra code
            Thread.Sleep(5000);

            InternetExplorer objInternetExplorer = null;
            HTMLDocument     htmlDocument;
            DataTable        dtRecords = new DataTable();

            dtRecords = ReadExcelToDT(@"\challenge.xlsx", "Sheet1");
            for (int j = dtRecords.Rows.Count - 1; j >= 0; j--)
            {
                if (dtRecords.Rows[j][1] == DBNull.Value)
                {
                    dtRecords.Rows[j].Delete();
                }
            }
            dtRecords.AcceptChanges();

            int i = 0;

            //Getting InternetExplorer from all open windows
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); shellWindows = new SHDocVw.ShellWindows();
            foreach (InternetExplorer browser in shellWindows)
            {
                if (browser.LocationURL.ToLower().Contains("www.rpachallenge.com"))
                {
                    objInternetExplorer = browser;
                    break;
                }
            }
            foreach (DataRow dr in dtRecords.Rows)
            {
                if (objInternetExplorer != null)
                {
                    //Get HTML content in HTMLDocument from InternetExplorer object
                    htmlDocument = objInternetExplorer.Document;
                    if (i == 0)
                    {
                        HTMLButtonElement startBtn = (HTMLButtonElement)htmlDocument.getElementById("start");
                        startBtn.click();
                        i++;
                    }

                    var divElementsCollection = htmlDocument.getElementsByTagName("div");
                    //js-inputContainer input-group
                    //js-inputContainer input-group
                    if (divElementsCollection != null)
                    {
                        foreach (HTMLDivElement mainDiv in divElementsCollection)
                        {
                            if (mainDiv != null)
                            {
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("First Name"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["First Name"].ToString();
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Last Name"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Last Name"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Company Name"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Company Name"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Role in Company"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Role in Company"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Address"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Address"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Email"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Email"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                                if (mainDiv.innerText != null && mainDiv.innerText.Trim().Equals("Phone Number"))
                                {
                                    var inputCollection = mainDiv.getElementsByTagName("input");
                                    foreach (HTMLInputElement input in inputCollection)
                                    {
                                        if (input != null)
                                        {
                                            input.value = dr["Phone Number"].ToString();;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    var btnSumbitCollection = htmlDocument.getElementsByTagName("input");
                    foreach (HTMLInputElement btnSubmit in btnSumbitCollection)
                    {
                        if (btnSubmit != null && btnSubmit.value.Trim().Equals("Submit"))
                        {
                            btnSubmit.click();

                            break;
                        }
                    }
                }
            }

            Console.ReadLine();
        }
Esempio n. 30
0
        private void Internet_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                InternetExplorer ie         = new InternetExplorer();
                IWebBrowserApp   webBrowser = ie;

                webBrowser.Visible = true;
                webBrowser.GoHome();
                IWebBrowserApp wb = (IWebBrowserApp)ie;

                wb.Visible = true;
                wb.GoHome();

                internetCount++;
            }
            catch
            {
                System.Windows.MessageBox.Show("internet connect");
            }

            //인터넷 최대화 단축키
            keybd_event(0x5B, 0, 0, 0); // window key
            keybd_event(0x26, 0, 0, 0); // arrow up key
            keybd_event(0x5B, 0, 0x0002, 0);
            keybd_event(0x26, 0, 0x0002, 0);

            if (isInternet == false)
            {
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                IntPtr handle = GetForegroundWindow();
                foreach (SHDocVw.WebBrowser IE in shellWindows)
                {
                    if (IE.HWND.Equals(handle.ToInt32()))
                    {
                        while (IE.Busy == true || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                        try
                        {
                            doc = IE.Document as mshtml.HTMLDocument;
                        }
                        catch
                        {
                            System.Windows.MessageBox.Show("err");
                        }
                    }
                }
                if (doc != null)
                {
                    Uri    uri  = new Uri(doc.url);
                    String host = uri.Host;

                    if (host.Contains(youtube))
                    {
                        InternetY dlg = new Renewal.InternetY();
                        dlg.Show();
                        //isInternetY = true;
                    }
                    else if (host.Contains(facebook))
                    {
                    }
                    else // naver, daum, google etc. (default)
                    {
                        Internet dlg = new Renewal.Internet();
                        dlg.Show();
                        isInternet = true;
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Internet open error");
                }
            }
        }
Esempio n. 31
0
        // search input complete
        void Keyboard_Closed(object sender, EventArgs e)
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            IntPtr handle = GetForegroundWindow();

            foreach (SHDocVw.WebBrowser IE in shellWindows)
            {
                if (IE.HWND.Equals(handle.ToInt32()))
                {
                    doc = IE.Document as mshtml.HTMLDocument;
                }
            }
            if (doc != null)
            {
                // Document 속성 읽기
                Uri    uri  = new Uri(doc.url);
                String host = uri.Host;

                if (host.Contains(naver))
                {
                    //검색어 셋팅
                    IHTMLElement query = doc.getElementsByName("query").item("query", 0);
                    query.setAttribute("value", System.Windows.Clipboard.GetText());

                    //네이버검색버튼 : search_btn
                    doc.getElementById("search_btn").click();
                }
                else if (host.Contains(search_naver))
                {
                    mshtml.IHTMLElementCollection elemColl = null;
                    elemColl = doc.getElementsByTagName("button") as mshtml.IHTMLElementCollection;

                    foreach (mshtml.IHTMLElement elem in elemColl)
                    {
                        if (elem.getAttribute("class") != null)
                        {
                            if (elem.className == "bt_search spim")
                            {
                                IHTMLElement query = doc.getElementsByName("query").item("query", 0);
                                //검색어 셋팅
                                query.setAttribute("value", System.Windows.Clipboard.GetText());
                                elem.click();
                                break;
                            }
                        }
                    }
                }
                else if (host.Contains(daum) || host.Contains(google))
                {
                    IHTMLElement q = doc.getElementsByName("q").item("q", 0);
                    q.setAttribute("value", System.Windows.Clipboard.GetText());

                    IHTMLFormElement form_google = doc.forms.item(Type.Missing, 0);
                    form_google.submit();
                }

                else
                {
                    System.Windows.MessageBox.Show("naver google daum 쓰세요");
                }
            }
        }