public bool DisconnectNewVersion() { try { //Start(); if (au3 == null) { au3 = new AutoItX3Lib.AutoItX3(); } au3.WinActivate(APP_TITLE); Thread.Sleep(1000); int xx = au3.WinGetPosX(APP_TITLE); int yy = au3.WinGetPosY(APP_TITLE); int w = au3.WinGetPosWidth(APP_TITLE); int h = au3.WinGetPosHeight(APP_TITLE); //au3.MouseClick("left", xx + w/2, yy + h/2, 5, 5); au3.MouseClick("left", xx + w / 2, yy + 120, 1, 5); Thread.Sleep(5000); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
private bool Start() { try { if (au3 == null) { au3 = new AutoItX3Lib.AutoItX3(); } if (au3.WinExists(APP_TITLE) == 0) { var path = ProgramFilesx86() + "\\Hotspot Shield\\bin\\hsscp.exe"; logger.Info("path: " + path); au3.Run(path, "", au3.SW_SHOW); Thread.Sleep(8000); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
static int i = 0; //our incrementer /// <summary> /// The entry point, or main thread / main loop, of our program /// </summary> static void Main(string[] args) { au3 = new AutoItX3Lib.AutoItX3(); //initialize our au3 class library au3.AutoItSetOption("WinTitleMatchMode", 4); //advanced window matching thread = new Thread(new ThreadStart(threadtest)); //initialize and start our thread thread.Start(); if (au3.WinExists("Untitled - Notepad", "") == 0) //if an Untitled - Notepad document doesn't exist { au3.Run(@"C:\WINDOWS\SYSTEM32\notepad.exe", "", au3.SW_SHOW); //run notepad } else { au3.WinActivate("Untitled - Notepad", ""); //otherwise activate the window } string hWnd = ""; //let's use a window handle while (hWnd.Length == 0) //try to get a handle to notepad until it succeeds { hWnd = au3.WinGetHandle("Untitled - Notepad", ""); } while (au3.WinActive("handle=" + hWnd, "") == 0) //loop while it's not active { au3.WinActivate("handle=" + hWnd, ""); //and activate it Thread.Sleep(100); } while (au3.WinExists("handle=" + hWnd, "") != 0) //while the window exists, loop { //send our incrementing variable, i, to notepad, with a trailing | au3.ControlSend("handle=" + hWnd, "", "Edit1", i.ToString() + "|", 0); i++; //increment i Thread.Sleep(100); //short sleep so we don't burn CPU } //if the while loop exited--because there's no Untitled - Notepad--make the other thread stop executing threadshouldexecute = false; Console.Write("Press [ENTER] to continue..."); //tell the user to press ENTER to quit Console.ReadLine(); //pause until enter is pressed }
/// <summary> /// Execution starts here /// </summary> /// <param name="args"> Two agruments would be passed 1. Recovery file path 2. Sheet name for popup file. 3. Invoking Parent Process ID </param> static void Main(string[] args) { try { string filePath = args[0].ToString(); Console.WriteLine("FilePath" + filePath); _applicationPath = Application.ExecutablePath; int applicationFilePath = _applicationPath.LastIndexOf("\\", StringComparison.Ordinal); string workingDirectory = string.Empty; if (applicationFilePath >= 0) { workingDirectory = _applicationPath.Substring(0, applicationFilePath + 1); } DataSet dataset = GetDataSet(filePath); try { //Generate Autoit object. _objAutoit = new AutoItX3Lib.AutoItX3(); //Setting AutoIt Title match to Exact match. _objAutoit.AutoItSetOption("WinTitleMatchMode", 4); _parentProcessId = args[2]; } catch (Exception e) { KryptonException.Writeexception(e); } //Starting Infinite loop. //loop should run as long as parent process is running while (_isParentProcessRunning) { //Getting all windows beforehand. dynamic windowsList = _objAutoit.WinList("[REGEXPTITLE:^.*$]"); int winListCount = (int)windowsList[0, 0]; // List[0,0] give the count of windows. var windowTitleList = new List <string>(); //Populating non empty titles to windowTitleList. for (int j = 1; j <= winListCount; j++) { string title = (string)windowsList[0, j]; if (!string.IsNullOrEmpty(title)) { windowTitleList.Add(title); } } if (dataset.Tables.Count > 0) { for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { //First thing first, check if parent process is running //If parent process (Krypton.exe) is not running, exits from here try { Process.GetProcessById(int.Parse(_parentProcessId)); } catch (Exception e) { //Exception will occur only when parent process is not running _isParentProcessRunning = false; return; } //Get IE popup Title. string popupName = dataset.Tables[0].Rows[i]["PopUpTitle"].ToString().Trim(); //Get IE popup Title. string buttonName = dataset.Tables[0].Rows[i]["ButtonName"].ToString().Trim(); //Get the action need to be done. string action = dataset.Tables[0].Rows[i]["Action"].ToString().Trim(); //Populate data if provided. var data = dataset.Tables[0].Rows[i]["Data"].ToString().Trim(); if (windowTitleList.Contains(popupName)) { //Switching control based on action given. switch (action.ToLower()) { case "click": BtnClick(popupName, buttonName); break; case "keypress": KeyPress(popupName, data); break; case "close": _objAutoit.WinClose(popupName); break; case "run": case "execute": if (!File.Exists(_applicationPath + data)) { data = data + ".exe"; } //Create process information and assign data using (Process specialScriptProcess = new Process()) { specialScriptProcess.StartInfo.CreateNoWindow = false; specialScriptProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; specialScriptProcess.StartInfo.UseShellExecute = false; specialScriptProcess.StartInfo.FileName = data; specialScriptProcess.StartInfo.WorkingDirectory = workingDirectory; specialScriptProcess.StartInfo.ErrorDialog = false; // Start the process specialScriptProcess.Start(); specialScriptProcess.WaitForExit(10000); } break; } } System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(2000); } } } catch (System.Runtime.InteropServices.COMException) { Console.WriteLine(ConsoleMessages.REGISTER_AUTOIT); } catch (IndexOutOfRangeException) { Console.WriteLine(ConsoleMessages.INVALID_ARGUMNETS); } catch (Exception e) { Console.WriteLine(ConsoleMessages.PARALLEL_rECOVERY + e.Message + e.StackTrace); } }
public static string activateCurrentBrowserWindow() { // try to switch to most recent browser window, if you can try { string winTitle = Driver.Title; AutoItX3Lib.AutoItX3 objAutoit = new AutoItX3Lib.AutoItX3(); var windowList = (Object[,])objAutoit.WinList("[TITLE:" + winTitle + "; CLASS:IEFrame]"); int windowCount = (int)windowList[0, 0]; if (windowCount.Equals(1)) { //Setting window on top means you cannot manually switch to any other windows //If you need IE clicks to be stable, this has to be done objAutoit.WinSetOnTop(winTitle, "", 1); //Activate window and set to focus objAutoit.WinActivate(winTitle); } } catch (Exception) { // Ignore } return Property.HwndMostRecentWindow; }
/// <summary> /// Execution starts here /// </summary> /// <param name="args"> Two agruments would be passed 1. Recovery file path 2. Sheet name for popup file. 3. Invoking Parent Process ID </param> static void Main(string[] args) { try { string filePath = args[0].ToString(); Console.WriteLine("FilePath" + filePath); _applicationPath = Application.ExecutablePath; int applicationFilePath = _applicationPath.LastIndexOf("\\", StringComparison.Ordinal); string workingDirectory = string.Empty; if (applicationFilePath >= 0) { workingDirectory = _applicationPath.Substring(0, applicationFilePath + 1); } DataSet dataset = GetDataSet(filePath); try { //Generate Autoit object. _objAutoit = new AutoItX3Lib.AutoItX3(); //Setting AutoIt Title match to Exact match. _objAutoit.AutoItSetOption("WinTitleMatchMode", 4); _parentProcessId = args[2]; } catch (Exception e) { KryptonException.Writeexception(e); } //Starting Infinite loop. //loop should run as long as parent process is running while (_isParentProcessRunning) { //Getting all windows beforehand. dynamic windowsList = _objAutoit.WinList("[REGEXPTITLE:^.*$]"); int winListCount = (int)windowsList[0, 0]; // List[0,0] give the count of windows. var windowTitleList = new List<string>(); //Populating non empty titles to windowTitleList. for (int j = 1; j <= winListCount; j++) { string title = (string)windowsList[0, j]; if (!string.IsNullOrEmpty(title)) { windowTitleList.Add(title); } } if (dataset.Tables.Count > 0) { for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { //First thing first, check if parent process is running //If parent process (Krypton.exe) is not running, exits from here try { Process.GetProcessById(int.Parse(_parentProcessId)); } catch (Exception e) { //Exception will occur only when parent process is not running _isParentProcessRunning = false; return; } //Get IE popup Title. string popupName = dataset.Tables[0].Rows[i]["PopUpTitle"].ToString().Trim(); //Get IE popup Title. string buttonName = dataset.Tables[0].Rows[i]["ButtonName"].ToString().Trim(); //Get the action need to be done. string action = dataset.Tables[0].Rows[i]["Action"].ToString().Trim(); //Populate data if provided. var data = dataset.Tables[0].Rows[i]["Data"].ToString().Trim(); if (windowTitleList.Contains(popupName)) { //Switching control based on action given. switch (action.ToLower()) { case "click": BtnClick(popupName, buttonName); break; case "keypress": KeyPress(popupName, data); break; case "close": _objAutoit.WinClose(popupName); break; case "run": case "execute": if (!File.Exists(_applicationPath + data)) { data = data + ".exe"; } //Create process information and assign data using (Process specialScriptProcess = new Process()) { specialScriptProcess.StartInfo.CreateNoWindow = false; specialScriptProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; specialScriptProcess.StartInfo.UseShellExecute = false; specialScriptProcess.StartInfo.FileName = data; specialScriptProcess.StartInfo.WorkingDirectory = workingDirectory; specialScriptProcess.StartInfo.ErrorDialog = false; // Start the process specialScriptProcess.Start(); specialScriptProcess.WaitForExit(10000); } break; } } System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(2000); } } } catch (System.Runtime.InteropServices.COMException) { Console.WriteLine(ConsoleMessages.REGISTER_AUTOIT); } catch (IndexOutOfRangeException) { Console.WriteLine(ConsoleMessages.INVALID_ARGUMNETS); } catch (Exception e) { Console.WriteLine(ConsoleMessages.PARALLEL_rECOVERY + e.Message + e.StackTrace); } }