Automate another app from my C# app

S

Steve

In order to automate an external app I need to open the File menu and
click the fourth item in the menu. This item does not have a shortcut
assigned to it. Can anyone give me some pointers on how I can do
this.

Thanks,
Steve
 
F

Family Tree Mike

Steve said:
In order to automate an external app I need to open the File menu and
click the fourth item in the menu. This item does not have a shortcut
assigned to it. Can anyone give me some pointers on how I can do
this.

Thanks,
Steve
.

If the other app is a .net application, then perhaps you could link it into
your app and call its methods directly. If it is not a .net app, then I
suspect you will be needing to use windows api calls.

Mike
 
S

Steve

If the other app is a .net application, then perhaps you could link it into
your app and call its methods directly.  If it is not a .net app, then I
suspect you will be needing to use windows api calls.

Mike

Nope, its not a .Net app so yes I will have to use the APIs...I just
am not sure which ones to use. Was hoping somebody could give me some
pointers to get me started.

Thanks,
Steve
 
P

Peter Duniho

Steve said:
Nope, its not a .Net app so yes I will have to use the APIs...I just
am not sure which ones to use. Was hoping somebody could give me some
pointers to get me started.

Depending on what you know about the other application, variations on
the SendMessage() function may be useful. But, there's really nothing
about your question that is relevant to C# or .NET. The question is
off-topic here, and you will get much better help posting it to a
relevant newsgroup instead of here.

Pete
 
S

Steve

Depending on what you know about the other application, variations on
the SendMessage() function may be useful.  But, there's really nothing
about your question that is relevant to C# or .NET.  The question is
off-topic here, and you will get much better help posting it to a
relevant newsgroup instead of here.

Pete

Not sure why it is off topic here. The original question was how can
I open the File menu and click the fourth item down. And specifically
how do I do this with C#. I realize I left that last part out of my
original post but you will surely forgive me for thinking that it was
implied by the fact I posted the question in a C# group.

I have done this kind of thing in the past with APIs in VB6. However
now I need to do it in C#. Not having 20 years experience in C# and
more specifically the .Net framework as I do with VB (classic), I have
no idea what framework tools might be available to me.

If in fact there are no framework tools that would help (as indicated
by the previous poster), I would appreciate any pointers on how to go
about calling the requisite APIs in C#.

Thanks,
Steve
 
P

Peter Duniho

Steve said:
Not sure why it is off topic here. The original question was how can
I open the File menu and click the fourth item down. And specifically
how do I do this with C#. [...]

Right. And inasmuch as that was the original question, the original
question was on-topic. But the answer is: there's nothing in C# (or
rather, .NET…it's not like any programming language supports this kind
of thing).

Given that, the remaining parts of your questions – i.e. how
specifically you _can_ do this – have nothing to do with C# or .NET.
[...]
If in fact there are no framework tools that would help (as indicated
by the previous poster), I would appreciate any pointers on how to go
about calling the requisite APIs in C#.

You can start here: http://www.pinvoke.net/

There is also the microsoft.public.dotnet.framework.interop newsgroup.

Those are much more appropriate places to seek help than this one.

Note that if you insist on looking for help here, that's not really a
problem, except inasmuch as it will probably take longer for you to get
enough information to solve your problem, assuming you get enough at all.

Pete
 
J

Jeff Gaines

In order to automate an external app I need to open the File menu and
click the fourth item in the menu. This item does not have a shortcut
assigned to it. Can anyone give me some pointers on how I can do
this.

I see from a later post that you have done similar things in VB6. The bad
news is that there is no NET way of doing what you want, but the good news
is you can use the Windows API from C# in a very similar way to VB6.

So you need to write a prototype for the DLLs you need (www.pinvoke.net is
an excellent resource) and then use them pretty well as you did in VB.
 
A

AA2e72E

Did you use SendKeys with VB6?

In C#, System.Windows.Forms.SendKeys supports corresponding functionality.

The problem may be with estimating how long the action triggered by a
message/keystroke sent to the 'other' application takes, so that you can time
the next message/keystroke.
 
S

Steve

Well I found my solution. Thought I would post it here in case
anybody else happens along this thread looking for a way to automate
another app with .Net.

It turns out M$ has given us a Framework tool designed to do just
these things. The tool is the UI Automation Library found in the
namepsace System.Windows.Automation. This library provides access to
all UI elements on the desktop in a higherarcial fashion where the
desktop itself is the at the top of the higherarchy. The library
provides methods for finding, referencing and manipulating windows of
all types (WPF, Win32 forms, etc.). There are a couple of really good
articles about this library and how to use it here:
http://msdn.microsoft.com/en-us/magazine/cc163288.aspx
http://msdn.microsoft.com/en-us/magazine/cc163864.aspx

Hope this helps somebody else.
Steve
 
W

Weyland Yutani

Thanks Steve, I've been looking all over for a similar
solution and have been doing winAPI calls myself. I'd like to
use the namespace you've found - do you have an example you
can share?
 

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