C# Hook External Applications Installer

Posted on 2011-03-20
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


DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Upgrading my SSIS package in VS 2012 6 86
orderby list (from Json) 1 29 Excel Add-in 2 16
Return array 3 20
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

756 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