C# Hook External Applications Installer

Posted on 2011-03-20
Medium Priority
Last Modified: 2013-12-17
I am designing an Installer Process Recorder application to integrate into a larger Build Management application i will complete at a later date.

I wish to record the steps a user follows when installing an application, for example MySQL. For instance the user presses 'Ok' 'Next' 'I accept License' etc etc. I wish to record these steps and when my app is run on another machine, it will install MySQL automatically using the same steps as the original installation.

I have looked into MSI transformations but need the solution to be able to handle EXE installers and i would like to integrate it into a larger management application at a later date so i have decided to try and code it.

I have never coded in c# but used to program in Java so am hopeful i can pick it up.
In my head i expect to start my app and select the installer i wish to work with. Pressing the record button will launch the installer (MySQL). I would like to record the installers GUI calls / events. When my app is in replay mode I would like to try and send the same method calls so the Mysql installer thinks the buttons are being pressed by a user.

Does anyone know why this wouldn’t be possible in C#. I have read that C# cannot use global hooks except for mouse and keyboard. If I launched the installer from within my application thread, would I be able to record the method calls via hooks that way?
Any advice would be greatly appreciated.
Question by:Jonesey007
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
  • 5
  • 4
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35181014
Out of curiosity, what EXE-based installers do you have or foresee using in the future?
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35181131
You are right, global hooks are not directly possible in managed .Net (you can Google "global hook c#" for some alternatives) - one option is to use a C++ DLL that can interact with your C# application.

Another possibility is to manually record window titles & handles, and use FindWindow, EnumChildWindows and SendInput API's to replay the macro.

Although I'm wondering if a keyboard and mouse global hook might not be sufficient...

Also, I asked about what EXE installers you've got mostly because you seemed to have singled-out MySQL, which is readily available as an MSI. ;)

Author Comment

ID: 35181909
Hi Tgerbert

Since posting my question i have found an example which ties in with your FindWindow EnumChildWindows and SendInput solution.
So im quite excited that i might be able to get this working.

Yeah MySQL is a bad example, I cant think off the top of my head but im pretty sure the majority of our drivers are EXE's. And i know a few of our in house applications are.
I want to integrate this solution into a Management Application to produce and document the full software build so am happy to try and code it.

Thanks again for all the help


Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

LVL 33

Expert Comment

by:Todd Gerbert
ID: 35181972
I haven't gotten 'round to it yet, but was gonna attempt an example using global mouse/keyboard hooks, figuring you might be able to capture what messages are sent to which windows during install - so long as it's safe to assume that all keyboard & mouse input, during recording, is related to the install, and replay the list wind FindWindows/EnumWindows/SendInput.

I still think you're better off customizing the installs, even an EXE installer is almost guaranteed to have accept a "/s" switch (or something) to make it run unattended - I think that would prove much more reliable than replaying keyboard/mouse input, but lemme see what I can come up with when I get some time this afternoon.

Author Comment

ID: 35182043
Thank you very much tgerbert, i'm very interested to hear what you find.
All mouse / keyboard activity will be related to the installer, there are no instances where you have to jump between installers / applications.
I'm going to start coding tonight but i'll be pretty slow because i havnt used C# and Visual Studio before so it might take me a while to get up and running. Really appreciate your help.


LVL 33

Expert Comment

by:Todd Gerbert
ID: 35189281
Okay, well I was thinking you could use SetWindowsHookEx to install a low-level global mouse hook, and get notified of events like clicks, and then note the caption of the window that received the event and it's parents, if any.

The problem is, though, that a low-level mouse hook isn't given the handle to the target window.  A regular mouse hook would, but to install such a hook globally requires code be written in a native C++ DLL.


Author Comment

ID: 35189374
Ah i see, thats interesting
If you have 2 mins could you check out the link i send earlier
I was thinking i could use a similar concept
LVL 33

Accepted Solution

Todd Gerbert earned 2000 total points
ID: 35195169
Yeah, that's just about exactly what I was thinking to re-play your recorded "macro."

That doesn't really do anything for you in terms of recording though - though you could use a simple text file just to list window captions and actions by hand, e.g.
findwindow "Welcome to MySQL Install"
clickbutton "Next"
findwindow "Enter Admin password"
entertext "secret"
clickbutton "Finish"

Open in new window

And then use those API's mentioned in the link you posted to re-do those actions.

Author Comment

ID: 35196877
That looks great, thanks tgerbert

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

752 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