AppActivate and Send Keys not working correctly
-
Okay, I am trying to automate the download of data from a web based database. I can automate the login in and getting to the right pages, but when I try to download the database I get a "File Download - Security Warning" popup message box. I have tried to use AppActivate to put the focus on the message box and then send the keys to click the save button on the popup message box. This doesn't work correctly. The AppActivate seems to activate the message box, but when I send the keys it sends to the visual studio menus. Could someone point me in the direction of an article or explain to me how to make this work correctly? I have used Goggle (where I got the code I am using) but I can't find anything that says different than what I am doing. I am not using this on a windows form it is an aspx page. (Sample code that I am using)
Dim objShell objShell = CreateObject("WScript.Shell") AppActivate("File Download - Security Warning") objShell.SendKeys.Send("%S") objShell.SendKeys.Send("{Enter}")
Thanks in advance for any assistance with this problem.If you can’t have fun at work, then why go to work?
-
Okay, I am trying to automate the download of data from a web based database. I can automate the login in and getting to the right pages, but when I try to download the database I get a "File Download - Security Warning" popup message box. I have tried to use AppActivate to put the focus on the message box and then send the keys to click the save button on the popup message box. This doesn't work correctly. The AppActivate seems to activate the message box, but when I send the keys it sends to the visual studio menus. Could someone point me in the direction of an article or explain to me how to make this work correctly? I have used Goggle (where I got the code I am using) but I can't find anything that says different than what I am doing. I am not using this on a windows form it is an aspx page. (Sample code that I am using)
Dim objShell objShell = CreateObject("WScript.Shell") AppActivate("File Download - Security Warning") objShell.SendKeys.Send("%S") objShell.SendKeys.Send("{Enter}")
Thanks in advance for any assistance with this problem.If you can’t have fun at work, then why go to work?
SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Do you know of a good website or article that explains how to do this? I have been working on this about a week and it is the hold up of me finishing this project. I will try googling it, but if you know of a good resource that would be appreciated. Thanks
If you can’t have fun at work, then why go to work?
-
SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Thanks for the information. I found some code but I'm not quite understanding it. Below is the snippet I am using:
Dim docName = FindWindow(vbNullString, "File Download - Security Warning")
Const BM_CLICK As Integer = &H102
SendMessage(docName, BM_CLICK, 0, 0)
I have the following two questions: What does the &H102 stand for? And where or how do I tell it that I want the saved button clicked? The save button does have the short cut key of Alt-S that I can send, but I don't understand where that information goes. Thank you for any assistance with this issue.
If you can’t have fun at work, then why go to work?