How to detect another program installing?

This is a discussion on How to detect another program installing? within the Windows Programming forums, part of the Platform Specific Boards category; Can someone please point me in the right direction? I need to write a 'sub-program' to be used with a ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Florida
    Posts
    19

    How to detect another program installing?

    Can someone please point me in the right direction?

    I need to write a 'sub-program' to be used with a larger project I have in progress.

    The program needs to monitor Windows for any new programs installing. As soon as another program completes it's installation, I need my program to pop up a window remininding me to do certain things in my program. I just need to know how to monitor any new program installations, and trigger my message window. I know how to do the message window, of course, I just need some direction with the monitoring aspect.

    Thanks for any help!

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,623
    Somewhere in the registry windows has some keys that keep a list of installed programs. (That's where "Add / Remove Programs" gets them from) But i forget where they are.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,623
    Ah ha, you find them at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Is everything being installed at the same time, so in effect installing the 2nd program is just a "subroutine" of installing the first program?

    Or are they separate events, where P2 can be optionally installed even after P1 has been installed?

    Is P1 even running when P2 is installed ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Florida
    Posts
    19
    Actually, the 'sub-program' to my main program needs to monitor when ANY new programs are installed. Like if someone installed MS Office, or Nero Burning Rom, or any program from anyone, preferably using the msiInstaller. My program in a sense needs to "sort of" monitor the event viewer for the msiInstaller information event. I know not all programs use the msiInstaller to install their software, so my program probably won't be able to detact EVERY new software being installed....although I would really like it to.

    And, no, my main program doesn't run in the background, I just need this sub-program to monitor any new third party, or even MS software being installed, then after their new software is installed, this sub-program would pop up a 'reminder' window, notifying me that new software was installed, reminding me to run MY main program after. Basically I wrote a backup program, and I need to be reminded to run a new backup only after any new software is installed.

    Thanks for the responses and help! Without you I would still be in the stone ages.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Florida
    Posts
    19
    Thank you for the above registry key, but would that be no different than checking the Program Files folder? I really don't want to run my program every 10 minutes to compare the contents of that folder or the above key (I really don't know how to acces the registry with C++ either), I would like to know how to write a 'silent' and small program to always run in the background to monitor for any new software installations immediately.

    I guess this would be writing a service, I just don't know how or where to constantly monitor for installations using C++, their is a vbscript way of monitoring the WMI for certain, but I'm not that up to date with my vbscripting, I would prefer to write it entirely in C or C++.
    I'm a little rusty, so a 1 line syntax example or something would be geatly appreciated!

    Thanks again for your input!

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    My program in a sense needs to "sort of" monitor the event viewer for the msiInstaller information event
    You may want to use DispHelper and possibly use a variation of the following snippet in a service to monitor msi installs.

    Code:
    #pragma comment( lib, "user32.lib" )   // Search for user32.lib while linking
    
    #include <windows.h>
    #include "disphelper.h"
    #include <wchar.h>
    #include <iostream>
    using namespace std;
    
    
    /* **************************************************************************
     * getWmiStr:
     *   Helper function to create wmi moniker incorporating computer name.
     *
     ============================================================================ */
    static LPWSTR getWmiStr(LPCWSTR szComputer)
    {
        static WCHAR szWmiStr[256];
    
        wcscpy(szWmiStr, L"winmgmts:{impersonationLevel=impersonate}!\\\\");
        if (szComputer) wcsncat(szWmiStr, szComputer, 128);
        else            wcscat (szWmiStr, L".");
    
        wcscat(szWmiStr, L"\\root\\cimv2");
    
        return szWmiStr;
    }
    
    
    void EnumerateMSI(LPCWSTR szComputer)
    {
        CDispPtr wmiSvc, colQuickFixes;
        CDhStringA szCategory, szEventCode, szEventType;
        try
        {
            dhCheck( dhGetObject(getWmiStr(szComputer), NULL, &wmiSvc) );
            dhCheck( dhGetValue(L"%o", &colQuickFixes, wmiSvc, L".ExecQuery(%S)",
                L"SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Application' ") );
    
            FOR_EACH(objQuickFix, colQuickFixes, NULL)
            {
                dhGetValue(L"%s", &szCategory,      objQuickFix, L".Category");
                dhGetValue(L"%s", &szEventCode, objQuickFix, L".EventCode");
                dhGetValue(L"%s", &szEventType, objQuickFix, L".EventType");
                if( stricmp(szEventCode, "11728") == 0 )
                {
                    cout << "EventCode: "     << szEventCode      << endl
                        << "Category: "  << szCategory << endl
                        << "EventType: "   << szEventType    << endl << endl;
                }
            } 
            NEXT_THROW(objQuickFix);
        }
        catch (string errstr)
        {
            cerr << "Fatal error details:" << endl << errstr << endl;
        }
    }
    
    int main(void)
    {
        CDhInitialize init;
        dhToggleExceptions(TRUE);
        printf( "Enumerating MSI event 11728 entries\n");
        EnumerateMSI(L".");
        return 0;   
    }

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Florida
    Posts
    19
    That appears to be exactly what I was looking for. I will check out the info on DispHelper and write a service incorporating it. I don't have any experience writing services, but I guess now would be a good time to learn.

    Thanks tremendously!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21