process.start & fill app form

E

ep.

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
 
F

Family Tree Mike

I doubt the application (app.exe) has had time to start by the time you try
and activate it. Try a delay of a few seconds before activating it.
 
K

kimiraikkonen

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
 
E

ep.

This program sounds as though its what I need. It does not compile
b/c there no main and no declaration for Timer1. I'm just an upstart
visual basic programmer so I'm unclear on some of the basics.
thx.,
ep.
 
K

kimiraikkonen

This program sounds as though its what I need.  It does not compile
b/c there no main and no declaration for Timer1.  I'm just an upstart
visual basic programmer so I'm unclear on some of the basics.
thx.,
ep.













- Show quoted text -

The last sample i've posted assumes that you have a Winform
application and "Timer1" is placed on your form. As i tested on .NET
2.0, it must work fine using with timer control and if you don't use
timer, AppActivate function returns a kind of "Process ID not found"
exception surprisingly. You'd better re-read my previous post/codes
hoping to help you.

Thanks,

Onur Güzel
 
E

ep.

I've tried to follow the instructions from your previous posts. I think I've
gotten
most of it, but the correct syntax (so it compiles) is not so easy to program.
I compiled the enclosed code attempt with the command line compiler
(Framework.NET/v3.5) and received 6 or 7 syntax errors. What would you
suggest I can do to fix these.
-----------------------------------------------------------------------------------------
'----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 Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Diagnostics
Module Module1
Public Class Form1 Inherits System.Windows.Forms.Form
Dim ProcessID As Integer
Dim Timer1 As Timer
Sub RunProcess()
ProcessID = Process.Start("c:\myapp.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
Public Sub Main()
Application.Run(New Form1)
End Sub
End Module
'----End-------
 
K

kimiraikkonen

I've tried to follow the instructions from your previous posts.  I think I've
gotten
most of it, but the correct syntax (so it compiles) is not so easy to program.
I compiled the enclosed code attempt with the command line compiler
(Framework.NET/v3.5) and received 6 or 7 syntax errors.  What would you
suggest I can do to fix these.
---------------------------------------------------------------------------­--------------
'----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 Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Diagnostics
Module Module1
Public Class Form1 Inherits System.Windows.Forms.Form
Dim ProcessID As Integer
Dim Timer1 As Timer
Sub RunProcess()
ProcessID = Process.Start("c:\myapp.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
Public Sub Main()
        Application.Run(New Form1)
End Sub
End Module
'----End-------

Try to compile as a new Winform project within VS IDE. As it seems you
have tried to compile Winform objects from command-line
compiler(VBC.exe), it may require additional references explictly such
as System.Windows.Forms etc.

And if you still insist on compiling your winform project from command
line, you can check this out:
http://duncanmackenzie.net/samples/commandline/default.aspx

Hope this helps,

Onur Guzel
 
E

ep.

I selected the IDE route with VB 2008 Express Edition. This time the
compilation
your code resulted in only one error:
"Handles clause requires a WithEvents variable defined in the containing
type or
one of its base types." What's this about?
 
K

kimiraikkonen

I selected the IDE route with VB 2008 Express Edition. This time the
compilation
your code resulted in only one error:
"Handles clause requires a WithEvents variable defined in the containing
type or
one of its base types." What's this about?

For which object? Apparently, you need to add WithEvents keyword to
make object's events recognized by compiler. Assuming "WithEvents"
keyword is missing for Timer control(because you didn't tell the
object name), just place a Timer control from your toolbox and double-
click on it. WithEvents will be created automatically for you by VS in
Form1.Designer.vb file. Then place the code block of Timer in your
Form1.vb. That's all.

or insert the full syntax of "WithEvents" into your Form1.Designer.vb
file as follows:

Friend WithEvents Timer1 As System.Windows.Forms.Timer

...do the same for button if required.

Hope this helps,

Onur Güzel
 
E

ep.

I've gotten this prog to compile thanks to the feedback above. A little off
topic; is VB used a lot in the real world?

The prog w/ timer mostly runs. It does start the app, however I receiver an
error: "unrecognized
process id" from the ActivateApp statement (even if the delay is 10 secs).
What's going on
with that?
 
K

kimiraikkonen

I've gotten this prog to compile thanks to the feedback above.  A little off
topic; is VB used a lot in the real world?

Besides C++, VB.NET may be used widely especially at enterprise-level
as a .NET language combining with ADO.
The prog w/ timer mostly runs.  It does start the app, however I receiver an
error: "unrecognized
process id" from the ActivateApp statement (even if the delay is 10 secs)..  
What's going on
with that?

Tried with "notepad.exe" in a Winform app and sample works, don't know
how much time after your application needs to start and make sure you
set a reasonable interval value in properties window for Timer
control.

Onur Güzel
 
E

ep.

1. Any cool vb application websites?
2. Regarding the app we've been discussing, is "process.start" blocking or
non-blocking?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top