CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #9
    Join Date
    Sep 2004
    Posts
    236

    Arrow Re: Is it possible to find out what programs are installed in the start menu?

    Thanks a ton eero_p I think you may have found exactly what I was needing!!

    I've never worked with the registery but I am looking at the location you said:
    \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    and I see Display Name is exactly what I need to copy to a text file

    When I click the Uninstall folder It shows the following:
    Name: Default
    Type: REG_SZ
    Data: Value not Set

    but all the folders under the Uninstall folder have more data such as:
    Display Name: HP Photosmart
    Type: REG_SZ
    Data: HP Photosmart

    I found this example that emerates the subkeys but i'm not sure if its what i'm looking for:
    http://msdn2.microsoft.com/en-us/library/ms724256.aspx

    Code:
    // QueryKey - Enumerates the subkeys of key and its associated values.
    //     hKey - Key whose subkeys and values are to be enumerated.
    
    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    
    #define MAX_KEY_LENGTH 255
    #define MAX_VALUE_NAME 16383
     
    void QueryKey(HKEY hKey) 
    { 
        TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
        DWORD    cbName;                   // size of name string 
        TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
        DWORD    cchClassName = MAX_PATH;  // size of class string 
        DWORD    cSubKeys=0;               // number of subkeys 
        DWORD    cbMaxSubKey;              // longest subkey size 
        DWORD    cchMaxClass;              // longest class string 
        DWORD    cValues;              // number of values for key 
        DWORD    cchMaxValue;          // longest value name 
        DWORD    cbMaxValueData;       // longest value data 
        DWORD    cbSecurityDescriptor; // size of security descriptor 
        FILETIME ftLastWriteTime;      // last write time 
     
        DWORD i, retCode; 
     
        TCHAR  achValue[MAX_VALUE_NAME]; 
        DWORD cchValue = MAX_VALUE_NAME; 
     
        // Get the class name and the value count. 
        retCode = RegQueryInfoKey(
            hKey,                    // key handle 
            achClass,                // buffer for class name 
            &cchClassName,           // size of class string 
            NULL,                    // reserved 
            &cSubKeys,               // number of subkeys 
            &cbMaxSubKey,            // longest subkey size 
            &cchMaxClass,            // longest class string 
            &cValues,                // number of values for this key 
            &cchMaxValue,            // longest value name 
            &cbMaxValueData,         // longest value data 
            &cbSecurityDescriptor,   // security descriptor 
            &ftLastWriteTime);       // last write time 
     
        // Enumerate the subkeys, until RegEnumKeyEx fails.
        
        if (cSubKeys)
        {
            printf( "\nNumber of subkeys: %d\n", cSubKeys);
    
            for (i=0; i<cSubKeys; i++) 
            { 
                cbName = MAX_KEY_LENGTH;
                retCode = RegEnumKeyEx(hKey, i,
                         achKey, 
                         &cbName, 
                         NULL, 
                         NULL, 
                         NULL, 
                         &ftLastWriteTime); 
                if (retCode == ERROR_SUCCESS) 
                {
                    _tprintf(TEXT("(%d) %s\n"), i+1, achKey);
                }
            }
        } 
     
        // Enumerate the key values. 
    
        if (cValues) 
        {
            printf( "\nNumber of values: %d\n", cValues);
    
            for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++) 
            { 
                cchValue = MAX_VALUE_NAME; 
                achValue[0] = '\0'; 
                retCode = RegEnumValue(hKey, i, 
                    achValue, 
                    &cchValue, 
                    NULL, 
                    NULL,
                    NULL,
                    NULL);
     
                if (retCode == ERROR_SUCCESS ) 
                { 
                    _tprintf(TEXT("(%d) %s\n"), i+1, achValue); 
                } 
            }
        }
    }
    
    void _tmain(void)
    {
       HKEY hTestKey;
    
       if( RegOpenKeyEx( HKEY_CURRENT_USER,
            TEXT("SOFTWARE\\Microsoft"),
            0,
            KEY_READ,
            &hTestKey) == ERROR_SUCCESS
          )
       {
          QueryKey(hTestKey);
       }
    }

    When they say "KEY"
    Do they refer to that long string of characters and numbers as the folder name when you look in regedit?

    like:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{00010409-78E1-11D2-B60F-006097C998E7}

    and the { .... } is the key?

    So really I should be looking for functions that can read all the "KEYS" under the directory:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

    and access the KEYS DisplayName if a KEy has it, copy the DisplayName's value to a file;
    if the key doesn't have a DisplayName value, skip that key?

    Anyone know of any functions for accessing's a key's data if thats what its called?

    I think this will direct me to the right directory but i'm not sure
    how to go about reading the key's once I get to the directory because I don't know what the key value will be.

    Code:
    void _tmain(void)
    {
       HKEY hTestKey;
    
       if( RegOpenKeyEx( HKEY_CURRENT_USER,
            TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"),
            0,
            KEY_READ,
            &hTestKey) == ERROR_SUCCESS
          )
       {
          QueryKey(hTestKey);
       }
    
    }
    Last edited by voidflux; May 15th, 2007 at 06:06 PM.
    Computer Science/Engineering
    @ PSU
    Co-oping with IBM's zSeries team! wee
    VS 2005.net
    http://www.personal.psu.edu/css204/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured