• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

C# Hook External Applications Installer

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
Jonesey007
Asked:
Jonesey007
  • 5
  • 4
1 Solution
 
Todd GerbertIT ConsultantCommented:
Out of curiosity, what EXE-based installers do you have or foresee using in the future?
0
 
Todd GerbertIT ConsultantCommented:
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
 
Jonesey007Author Commented:
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
Technology Partners: 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!

 
Todd GerbertIT ConsultantCommented:
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
 
Jonesey007Author Commented:
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
 
Todd GerbertIT ConsultantCommented:
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
 
Jonesey007Author Commented:
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
 
Todd GerbertIT ConsultantCommented:
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
 
Jonesey007Author Commented:
That looks great, thanks tgerbert
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now