Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
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:
VB
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


I hope you can help me with this issue,
thanks in advance.
Posted
Comments
[no name] 11-Jul-14 8:22am    
Is it really necessary for you to re-invent the wheel? Try Auto-It as it can do this and more already out of the box, and it's free.

1 solution

You'll have get a list of all the open windows on the machine, and wait for the message box to pop up and be in the list. Then you can select it and send an enter key to close it.

Just try Googling "vb.net enumerate open windows" and you'll find many code examples.

-Pete
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900