Solved

use C# program to control an external program

Posted on 2009-05-06
4
1,219 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
  • 2
4 Comments
 
LVL 85

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 85

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
PrintingFoundIt(Almost!(Damn!)) 1 37
Create a WebAPI using a generic return parameter 9 41
insert value of checklistbox checked 4 38
Sort GridView by ID Descending 1 24
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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