Solved

use C# program to control an external program

Posted on 2009-05-06
4
1,211 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now