Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

use C# program to control an external program

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

670 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