Solved

C# Hook External Applications Installer

Posted on 2011-03-20
9
688 Views
Last Modified: 2013-12-17
Hi
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.
Thanks
0
Comment
Question by:Jonesey007
  • 5
  • 4
9 Comments
 
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?
0
 
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. ;)
0
 

Author Comment

by:Jonesey007
ID: 35181909
Hi Tgerbert

Since posting my question i have found an example which ties in with your FindWindow EnumChildWindows and SendInput solution.
http://www.codeproject.com/KB/cs/WindowsAPIsFromCS.aspx
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

Pete

0
 
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.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:Jonesey007
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.

Cheers

Pete
0
 
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.

0
 

Author Comment

by:Jonesey007
ID: 35189374
Ah i see, thats interesting
If you have 2 mins could you check out the link i send earlier
http://www.codeproject.com/KB/cs/WindowsAPIsFromCS.aspx
I was thinking i could use a similar concept
0
 
LVL 33

Accepted Solution

by:
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.
0
 

Author Comment

by:Jonesey007
ID: 35196877
That looks great, thanks tgerbert
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

746 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

12 Experts available now in Live!

Get 1:1 Help Now