Results 1 to 3 of 3

Thread: Trying some automation and I have run into a snag

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    Question Trying some automation and I have run into a snag

    I am using Visuasl Studio 2015 Community edition on Windows 10 for this.

    Basically, I have a program that I want to start-up and have it automatically log in at Windows startup. The first thing I thought was to ask the software publisher to add a feature to start the program at startup and to have it auto-login. However, they have been slow to respond, so I thought I would take matters into my own hands.

    I have written a VB program that launches the program in question and then sends keys to the program to pass the password to it and log in. I'm using AutoItX COM to handle passing the keystrokes since I cannot pass the keystrokes to the program using Windows API, as far as I can tell.

    I am planning on using this on various different machines, all running Windows 10. Each site seems to have its own idiosyncrasies on the time of getting to the desktop and then allowing programs to actually do things. For instance, the first computer I set this program up on, I have a sleep timer in the program for 2 seconds. On the second computer, I had to up this time to 6 seconds; without the 6 seconds, my program wouldn't pass the keystrokes to the launched program.

    That brings me to my dilemma. The third computer I am working with seems to be exceptionally slow. I have increased the sleep timer in my program up to 90 seconds and I am still not getting the keystrokes passed over to the launched program. Basically, I need to know if there is a simple way to determine when I can send the keystrokes, in code, so I can just write it in as a failsafe for future versions.

    Any suggestions on that or a better way to accomplish what I am doing?

  2. #2
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    477

    Re: Trying some automation and I have run into a snag

    You should be able to do this with Windows UI Automation. Here is what I would do.

    1. Start you program using MS task Scheduler, when Windows starts but with a few minute delay to allow all startup programs to be started, login scripts to complete, etc.
    2. Check if the target program is running if not start it.
    3. If you started it then use a loop to check for, wait, and keep looping, until the password field or the login button "exists" (more on this later)
    4. If the program was already started, check for some element that would indicate the program has already been logged in (an element that would not exist until logged in).
    5. If the program was already started AND has not been logged in then enter the same loop as step 3 to wait until the password and/or button exists).
    6. Once the password and/or login button exists THEN send the keystrokes (you should be able to use sendKey)

    To do this you will need to use the Microsoft Inspect.exe tool (Included with most Windows SDK. You may need to download). Inspect allows you to look at ALL Windows and ALL Form elements of each window and learn all kinds of details about them including their name. This should allow you to use Windows UI Automation to detect and access the fields on the login form.

    Topics you may need to investigate:
    1. How to use MS Task Scheduler
    2. How to obtain and use Inspect.exe (NOTE: MS spyxx.exe may also work but I like Inspect better)
    3. How to use MS UI Automation tools.
    4. How to use sendKey

    Here are some details about Inspect
    https://msdn.microsoft.com/en-us/library/windows/desktop/dd318521(v=vs.85).aspx

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2016
    Posts
    2

    Re: Trying some automation and I have run into a snag

    I will look into Inspect. I've used Spy++ but it doesn't give me all of the information I need sometimes.

    I'll have to look into delay start with Task Scheduler...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width