What is preferred method to start an app process and then fill in form fields?
The following prog does not compile (b/c AppActivate does not have the
correct param):
----------------------------------------------------------------------------------------
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Diagnostics
Module Module1
Sub Main()
Dim proc As Process = Process.Start("c:\app2020\app.EXE")
AppActivate(proc)
SendKeys.SendWait("22")
End Sub
End Module
To make AppActivate work, you should pass processID(Integer) or
Title(String) as parameter, see notepad sample on MSDN:
http://msdn.microsoft.com/en-us/library/dyz95fhy(VS.80).aspx
I would use that code at first sight, but i beleive it causes
ProcessID not found exception because of a kind of timing error:
' You can use Process.Start
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Diagnostics
Module Module1
Sub Main()
Dim ProcessID As Integer
ProcessID = Process.Start("c:\app2020\app.EXE").Id
AppActivate(ProcessID)
SendKeys.SendWait("22")
End Sub
End Module
So, stick with the following using a timer control that demonstrates a
WinForm app:
' ----Begin--------
' Note that before running app set timer's interval
' to a reasonable interval ike 1500 miliseconds
' or less or more as you wish in IDE.
Imports System.diagnostics
Public Class Form1
Dim ProcessID As Integer
Sub RunProcess()
ProcessID = Process.Start("c:\app2020\app.EXE").Id
End Sub
'Eg: Call sub on a button_click event
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
RunProcess()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
'Now call AppActivate
AppActivate(ProcessID)
SendKeys.SendWait("22")
Timer1.Enabled = False
End Sub
End Class
'----End-------
Hope this helps,
Onur Güzel