Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

use C# program to control an external program

Posted on 2009-05-06
4
Medium Priority
?
1,229 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 86

Accepted Solution

by:
Mike Tomlinson earned 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

876 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