2

I'm using the "native" C# SendKeys, as well as the AutoItX library, in C# (VS 2015) to manually enter login credentials into a login window on a Windows 10 computer.

For a long time, this has been working flawlessly. Then, apparently all of a sudden - with no changes done on my part - a delay of more than 1 minute is dominating all my code samples. That is - SendKeys.SendWait() and the Send() method of AutoItX both work, but it takes more than a minute to send the keys to the active window.

Here's my code:

I'm using Selenium WebDriver to open a Chrome browser window, and SendKeys.SendWait() or AutoItX.Send() to send the username and password, as well as TAB and ENTER to the login window.

 public void OpenAndLoginSelenium (string username, string password) {
        // Create the Selenium instance and navigate to the page:
        var driverService = ChromeDriverService.CreateDefaultService();
        driverService.HideCommandPromptWindow = true;
        Instance = new ChromeDriver(driverService);
        Instance.Navigate().GoToUrl("http://my-lab-drop2.telecomputing.com");

        // Alternative 1 - using AutoItX:
        AutoItX.WinActivate("Authentication required", "");
        AutoItX.Send(username);
        AutoItX.Send("{TAB}");
        AutoItX.Send(password);
        AutoItX.Send("{TAB}");
        AutoItX.Send("{ENTER}");

        // Alternative 2 - using SendKeys():
        SendKeys.SendWait(username);
        SendKeys.SendWait("{TAB}");
        SendKeys.SendWait(password);
        SendKeys.SendWait("{ENTER}");
}

Both alternatives work, but it takes 1 minute and 3 seconds (this delay seems to be pretty constant) before the first Send is executed. Nothing happens before this time has passed. There is no delay between the sends, however; As soon as the username string (in this example) is entered into the username field, the rest (TAB - enter password - ENTER) is executed quickly. Windows just waits one minute and three seconds before doing anything.

The login box is the standard systems login box created when Chrome enters a web page that requires authentication. I'm not able to post a link to the page, since it's an internal one, but please trust me on this. (Authenticating directly, using http://login:pass@url is not an option, since the process after entering the username/password involved a more complicated process than standard htauth, using som tokens and whatnot.)

There were no VISIBLE changes to the system between this working normally one afternoon and this delay suddenly being there the next morning, after a reboot of the system. I couldn't even find any log entries about any Windows updates or any other changes. But something has obviously happened - I'm just unable to find out what, and why this extreme and constant delay has come into effect.

UPDATE: The main question here is/was: Why is SendKeys() and AutoItX.Send() no longer working. The next question is: If there's no solution for this, what's the easiest alternative? What I need to do is type username and password into the login prompt of a browser (which is opened and further controlled by Selenium WebDriver) and log in to the web site. And enter text into and click buttons in things like file upload dialogs etc.

Frank H.
  • 1
  • 1
  • 11
  • 25
  • Is "prefer 32-bit" checked in your build properties by any chance? – Patrick Apr 03 '18 at 11:34
  • 1
    Ever since Vista, you shouldn't rely on `SendKey`s to another process, particularly if the target is elevated. They might not get there. Instead you might want to checkout _Microsoft UI Automation_ –  Apr 03 '18 at 11:36
  • 1
    @MickyD SendKey on an elevated privilege process shouldn't pass at all. I agree that MUIA is the way to go. 1998 VB6 sendkey times are over. – Franck Apr 03 '18 at 12:50
  • Patric: It was, but removing the check didn't help. – Frank H. Apr 04 '18 at 07:51
  • First of all, this has been working for more than a year. I've been especially fond of AutoItX, which is a well-known application/library for automating Windows operation. Easy or not. Second, I've not seen any documentation or examples using MUIA outside of pure CodedUI (or similr) tests, hence the question. – Frank H. Apr 05 '18 at 06:29
  • 2
    Delays of 60 seconds have very few explanations, there are just not a lot of things that take half a trillion cpu instructions. Just two in practice, network timeouts and anti-malware being anti. I see one obvious candidate. – Hans Passant Apr 05 '18 at 09:18
  • Network timeout it's not, because it works when doing it manually. It's a locally hosted, internal site. I've completely removed all malware on the computer. None of these did anything. Today, I ordered a complete wipe and reinstall of the OS on the computer; Let's see if that helps. – Frank H. Apr 05 '18 at 19:45
  • This is absolutely, 100% fantastic. I've reinstalled the system and everything, and it STILL doesn't work. SendKeys and equivalents are still delayed 1m4s, hence being 100% useless. – Frank H. Apr 10 '18 at 07:07

0 Answers0