I have to automate repetitive tasks of a windows application (no API), using VB.Net
.
What I did is simulate key strokes usually done by user.
I'm using System.Threading
, and initiating the application using a new process.
My PROBLEM is, that this app pops a message box when a task is done, and this message box sure disables the main app window, so I need to know when this message box is displayed to simulate the ENTER key stroke and proceed to next task.
Here is a sample of my code:
Imports System.Threading
Public Class Form1
Dim a As New Process
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
a.StartInfo.FileName = "C:\Program Files (x86)\CE\CE.exe"
a.Start()
AppActivate(a.Id)
For i = 1 To CInt(txt.Text)
DoTask()
Next
End Sub
Private Sub DoTask()
Thread.Sleep(1000)
SendKeys.SendWait("^(N)")
Thread.Sleep(500)
SendKeys.SendWait("{ENTER}")
Thread.Sleep(500)
SendKeys.SendWait("new check")
Thread.Sleep(500)
SendKeys.SendWait("{ENTER}")
Do While True
'Here I want to wait until a message box pops up by the application
'If message box displayed then exit do
Loop
SendKeys.SendWait("{ENTER}")
End Sub
End Class
Please help me with this. Thank you