4

I'm working on an application (A) that has to react and do something when a specific program (B) is installed on the system.

I've been seeing a lot of examples about listing programs already installed using the registry keys and some code to monitor status changes on programs and services using WMI.

I'm thinking I could use those combined to do what I want, say:

1. When my application (A) is started, check on the registry if my program (B) is installed or not (initial condition).

2. Then, monitor for service changes on the local machine from my application (A).

3. And every time a report of status changes comes from service "msiserver", re-check if my program (B) has been installed/uninstalled (initial condition has changed), and do something if so.

This sounds to me like I'm trying to reinvent the wheel here, and I wonder if any of you know if there's a more "natural " or "immediate" way to catch the moment/event when a specific program has been installed on the system ...or not :/

Additional considerations: The default location where the program (B) can be installed is variable, so monitoring for folders (like C:\Program Files) is not an option.

Thanks!

Community
  • 1
  • 1
safejrz
  • 544
  • 1
  • 14
  • 26

1 Answers1

1

I'm not aware of any mechanism that would allow you to subscribed to an OnInstalled type event. You'd have to loop and detect the installation status change. Perhaps using the Microsoft.Deployment.WindowsInstaller (DTF) library to enum products and/or components. Don't use WMI... the Win32_Product class is horribly slow and querying it causes reinstalls of applications. (Don't ask... it just sucks).

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • I know it sucks! however, since my program is already doing a lot of stuff with WMI I ended up implementing my solution instead. I wanted skip the polling process, use an async way, sad truth is it looks like such solution doesn't seem to exist yet. I'll give it an eye to your suggestion on my next project. – safejrz Dec 03 '13 at 22:13
  • There is nothing wrong with WMI per say, it's the Windows Installer provider that is horrible. If you write your own provider, WMI would be fine. – Christopher Painter Dec 03 '13 at 22:56