+ Reply to Thread
Results 1 to 13 of 13

Windows API, PowerShell, repeat keystrokes

  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Windows API, PowerShell, repeat keystrokes

    This might be a dumb question but here goes. I have a windows-based application that has a pop-up window asking me to confirm all the changes or some of the changes and then click on OK to continue. This task is repeated around 10,000 times (once for each confirmation of a change). Is there anyway to program Windows API or PowerShell (not sure which one is correct in this context) via Excel vba to just click on the accept all changes button in the pop-up and then the OK button. Currently I have to stare in front of the screen for a day or so waiting for the popup to appear then I click Enter (default answer is already highlighted) >> Tab (highlight the OK button) >> Enter (to confirm).

    If this is not possible then any other options are welcomed.

    Thanks.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Windows API, PowerShell, repeat keystrokes

    Hello abousetta ,

    Since this is a Windows based application and the default button is always selected, Excel may be able to answer for you automatically provided you are running a macro that clls this other application. If so then try adding Application.DisplayDialogs = False before you call the other program. Just remember to set it back to True before you exit the macro.

    If the above does not apply, it may be possible to do with the Windows API. However, the code needed to activate buttons in a dialog box is quite lengthy and complex. I can not comment on the use of PowerShell to do this.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Hi Leith,

    Thanks for looking at this for me. Here is some information I got from an automation program called AutoIt.

    The information on the target window and buttons are as follows:

    Please Login or Register  to view this content.
    Also this is something I picked up might or might not helpful but haven't gotten it to work in this situation:

    Please Login or Register  to view this content.
    Any help is highly appreciated.

    Thanks.

    abousetta

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Windows API, PowerShell, repeat keystrokes

    Hello abousetta,

    The ShellWindows displays only a specific classes of Windows. It will not work for dialogs, which are special Window class. The information you posted about the dialog is very typical and basic. Unfortunately, it is not helpful with regard to the API. The class information #32770 is the class id for all dialogs. It does not provide me with any information about the parent object which would be needed to correctly identify it from any other dialog that is displayed. The handle is useful but handles change as windows are created and destroyed and can not used as a permanent id method in code.

    Another potential problem with detection is if the dialog is not running in the same process as Excel. If not then a system hook would need to coded to detect the dialog. Unfortunately, system hooks written from Excel can be unstable and crash the system.

    Is there any other methods this program offers to allow you better control of the interface? Are there any commands or rules that you can access via VBA or COM?

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Hi Leith,

    Here is all the information that I got on the mother window:

    Please Login or Register  to view this content.
    I don't know if this is what you were talking about or not. If this is a big task then I can try to just work around it but I generally would appreciate help automating this if possible.

    abousetta

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Windows API, PowerShell, repeat keystrokes

    Hello abousetta,

    Looks like I will have to download AutoIt onto my system. From the write ups it seems like it should be possible to interface it with VBA. If you need an answer faster than waiting for me then you may want to post this question on one of the AutoIt support forums.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    HI Leith,

    AutoIt seems to be a really neat free standalone program for creating a macro for windows operations. I have just started to play around with it yesterday to allow me to see what the information required for automating EndNote (the program I am using) via Excel vba. Also I should mention that EndNote has an API of its own but the documentation doesn't show the process I am after. Below I have provided the links for AutoIt, EndNote and the EndNote API if they help:

    AutoIt: www.autoitscript.com

    EndNote: www.endnote.com

    EndNote API: http://endnote.com/en/endnote-api (download from here directly: https://www.dropbox.com/s/zcgssklram...ndNote_RDK.zip)

    abousetta

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Hi Leith,

    Thanks for all your help and guidance. I finally got it working. I was able to search for the Class and Title of the dialog box using a series of API functions. I used FindWindowLike instead of FindWindow to give a fuzzy approach to the name of the dialog box since I only know that part of it will be a constant. All the code is in the attachment and is just a series of modified pieces of code from all over the internet. Finally, I added a simple userform to escape the loop when the user is done with the updates. I am posting the main code below for anyone who might be interested.

    Thanks.

    abousetta

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Windows API, PowerShell, repeat keystrokes

    Hello abousetta,

    Well, I started updating my 4359 references, one at a time.... then I searched the net and found your wonderfully created Excel macro.

    While it is only about 1/8th of the way through my references, it looks like it is doing its proper job. I think Endnote should purchase your macro and integrate it into their program (with the ability to slow down the clicks so we can review the files that are being updated for occasional quality checks).

    Thank you for creating this helpful tool.

    middleoren

    P.S.
    I did have some crashes... but not sure if it is related to the macro or not.

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Hello and thanks for your kind comments. For a while, I thought I was the only one that ever updated all their references in EndNote .

    The only hiccup as you have noticed is that Endnote at time will crash. I've tried slowing down the macro with no change. The crash is random and I don't know why it happens. The only workaround I am doing is creating an extension to the above posted macro that will shut EndNote down if it crashes, restarts it and starts the process all over again. I'm not an IT pro so I do what I can, but so far everyone I know that is using it is managing OK.

    So what's you field of work? I mainly lead and coordinate evidence-based knowledge synthesis projects.

    abousetta

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Hi,

    I am attaching a newer version. This is the one I currently use. The added benefit is that you can see the name of the last citation that was updated. That way if EndNote crashes, you know where to begin from.

    Hope this helps.

    abousetta
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Windows API, PowerShell, repeat keystrokes

    Also in case you are interested in the code that terminates Endnote, you can find it here.

    Good luck.

    abousetta

  13. #13
    Registered User
    Join Date
    07-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Windows API, PowerShell, repeat keystrokes

    Thanks for the updated version... I will try that now.

    I am not sure if it helps... but it seems that when endnote crashes, it also crashes my internet access... I am not IT person either.

    I am in the physiotherapy world. www.canwellprogram.ca. That is a project I lead.

    Take care.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1