tags:

views:

79

answers:

4

Hello. Is it possible to telecontrol a program that is running by using c#? How to do that?

I have to convert about 500 files to a specific file format by opening it -> converting -> saving. So I want to create an alogrythm that will do the work.

Thank you for your help.

A: 

Yes it is. We can give more details on how to do it when you give more details on exactly what you're trying to do (where does the program reside? How is the program you are trying to control built? Does it support command line calling? Does it use COM or .NET assemblies you can connect to? etc etc).

Zippit
It does not use COM or.NET assemblies, and it doesn't support command line calling. The program is resides on my desktop.I know I have to get the handle of the program, but what to do next?
Forlan07
If it does not provide command line management, I'm afraid you cannot do it. You would better look for a program ready to do bulk/batch conversions, it would be more useful for you.
Baltasarq
@Baltasarq it's indeed possible to automate without CLIs though it requires some more work :)
Rune FS
I honestly haven't thought about macro recording solutions. However, there are many conversion tools (for images, texts...), that directly accept batch work, most of times through a CLI.
Baltasarq
A: 

You could use mouse and keyboard messages to control the program. This is pretty hackish, but it does work. For example, the mouse cursor can be control with Cursor.Position.

This might be easier in C++, though. Basically you grab the handle of the window and use SendMessage() to let it know what you want. WM_LBUTTONDOWN for example.

[DllImport("user32.dll")]
public static extern void SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

The lParam parameter contains the x/y cursor position. I've seen a minesweeper bot that uses this approach combined with some image processing logic, but if you want a simple hack, you can just hardcode the positions of the buttons.

+1  A: 

It seems to me that you are best using a scripting language for window automation. One of the most popular ones is AutoHotkey.

If you need to do in .NET you might want to look at the Windows Automation API coming with .NET 3.5.

Without knowing further details about the program that you want to automate it is not easy to give you more detailed advice.

0xA3
A: 

There are several test suites that allow you to "record macros" to simulate mouse clicks, key presses etc. You can then play these back many times. The intention is obviously to test UI interaction. But there's no reason this couldn't be used to automate a process as well.

Here are a couple (there are more but these are the ones we've used in the past):

http://www.ranorex.com/
http://www.autoitscript.com/autoit3/index.shtml

As previously mentioned you could also do it yourself by sending Windows Messages to the controls. That is probably a more robust solution in the long term, but will take some time to implement.

Zippit