Solved

use C# program to control an external program

Posted on 2009-05-06
4
1,222 Views
Last Modified: 2012-06-21
I am a newbie to C#, and I want to write a program that control the installation of an external program.  So, I don't have to waste time watching the installation and fill on all the textfields.
example:
on my C# program, I have a buttom to install Winamp to a computer, and after i click it, winamp installer will run, generally I have to click next, accept agreement, provide path etc.
can I use C# to input all those informations for me? so with one single click on the C#, the winamp will start until finish?
0
Comment
Question by:kamikaze2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24316577
Yes....it is possible...though probably tricky for a self-proclaimed "newbie".

Basically what you have to do is start the installation process with Process.Start()...passing the name of the installer in.
Then you start a polling loop that waits for the first dialog that needs user interaction to appear.  This will require the use of windows APIs such as FindWindow()/FindWindowEx().  Once your dialog appears, you would need to use FindWindowEx() to drill down thru the hierarchy of controls to find the desired button to click and use SendMessage() to send a BM_CLICK message (or simulate left button up/down clicks with a different API).

This type of code is difficult to write in a forum because it is SPECIFIC to the target app being automated.  You need to know specific window titles and/or classnames and need to be able to view the parent/child relationships between controls on each dialog window.  One tool that is extremely helpful for these types of apps is the FREE WinSpector: http://www.windows-spy.com/

Here is a small, manageable project to play with and get you started:
http://www.codeproject.com/KB/cs/WindowsAPIsFromCS.aspx

This guy describes a more complicated example:
http://www.codeproject.com/KB/cs/interopsignon.aspx

0
 
LVL 8

Expert Comment

by:mac-will
ID: 24319140
Maybe for something like you described a VB script would be easier?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24319352
The problem with any proposed VBScript solution would be that it relies on SendKeys() to simulate input...and that approach is notoriously easy to interrupt and "break" the automation process...

(it is technically possible though and may be enough for the author...who knows)
0
 

Author Comment

by:kamikaze2000
ID: 24325395
thank guys,
I got an idea how to do it now.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question