optymalizacja czytania z rejestru

0

Witam czy poniżej podany program można zapisać w jakiś prostszy sposób??
Biorąc pod uwagę powiedzmy iż bym chciał czytać wersje Office zainstalowanego na komputerze z rejestru sprawa jest trochę trudniejsza do wykonania i wielokronie trzeba się zapętlać tym samym kodem używając to ciągle poszerzonej ścieżki.

 #include <windows.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <string.h>

void installedprog();

int main()
{
    installedprog();

    return EXIT_SUCCESS;
}

void installedprog()
{
    HKEY hKey;
    DWORD cSubKeys;                //Used to store the number of
    DWORD maxSubkeyLen;         //Longest Subkey name length
    DWORD retCode;                  //Return values of calls
    const char *buf = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
    int i=0, len = 0;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf,0,KEY_ALL_ACCESS,&hKey);

    RegQueryInfoKey(hKey,        // key handle
    NULL,                        // buffer for class name
    NULL,                        // size of class string
    NULL,                        // reserved
    &cSubKeys,                // number of subkeys
    &maxSubkeyLen,                // longest subkey length
    NULL,                        // longest class string
    NULL,                        // number of values for this key
    NULL,                        // longest value name
    NULL,                        // longest value data
    NULL,                        // security descriptor
    NULL);                        // last write time

    if(cSubKeys>0)
    {
        char currentSubkey[MAX_PATH];

            for(;i < cSubKeys;i++)
            {
                DWORD currentSubLen=MAX_PATH;

                retCode=RegEnumKeyEx(hKey,           // Handle to an open/predefined key
                i,                                   // Index of the subkey to retrieve.
                currentSubkey,                       // buffer to receives the name of the subkey
                &currentSubLen,                      // size of that buffer
                NULL,                                // Reserved
                NULL,                                // buffer for class string
                NULL,                                // size of that buffer
                NULL);                               // last write time

                int len = strlen(buf) + strlen(currentSubkey);
                char bufor[len];
                strcpy(bufor, buf);
                strcat(bufor,currentSubkey);

                HKEY hKey2;
                RegOpenKeyEx(HKEY_LOCAL_MACHINE,bufor,0,KEY_ALL_ACCESS,&hKey2);

                char *value = "";
                DWORD value_size = 0;

                if (RegQueryValueEx(hKey2, "DisplayName", NULL, NULL,
                (BYTE *)value, &value_size) == ERROR_MORE_DATA)
                {
                    value = (char*) malloc(value_size+1);

                    RegQueryValueEx(hKey2, "DisplayName", NULL, NULL,
                    (BYTE *)value, &value_size);

                    printf("%s\n", value);
                }

                RegCloseKey(hKey2);
            }
    }

    RegCloseKey(hKey);
}
0

Chodzi mi o jakąkolwiek dokumentacje funkcji RegQueryInfoKey.
Myślałem o napisaniu własnej funkcji bo powyższa ma zbyt wiele rzeczy które i tak ustawiam na NULL.

0

Microsoft w swej przebiegłości udostępnia dokumentację api swoich bibliotek i technologii na MSDN.
http://msdn.microsoft.com/en-us/library/ms724902.aspx

0
LONG WINAPI RegQueryInfoKey(
  __in         HKEY hKey,
  __out_opt    LPTSTR lpClass,
  __inout_opt  LPDWORD lpcClass,
  __reserved   LPDWORD lpReserved,
  __out_opt    LPDWORD lpcSubKeys,
  __out_opt    LPDWORD lpcMaxSubKeyLen,
  __out_opt    LPDWORD lpcMaxClassLen,
  __out_opt    LPDWORD lpcValues,
  __out_opt    LPDWORD lpcMaxValueNameLen,
  __out_opt    LPDWORD lpcMaxValueLen,
  __out_opt    LPDWORD lpcbSecurityDescriptor,
  __out_opt    PFILETIME lpftLastWriteTime
);

jak mam te informacje wykorzystać by utworzyć nową funkcję ??

0

No choćby tak:

RegQueryInfoKey(hKey, // key handle
NULL, // buffer for class name
NULL, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&maxSubkeyLen, // longest subkey length
NULL, // longest class string
NULL, // number of values for this key
NULL, // longest value name
NULL, // longest value data
NULL, // security descriptor
NULL); // last write time

Chociaż może nie zrozumiałam, bo to nie jest wcale nowa funkcja... jaką nową funkcję? co ona ma robić?

0
hKey,        // Handle to an open/predefined key
i,                                // Index of the subkey to retrieve.
currentSubkey,                    // buffer to receives the name of the subkey
&currentSubLen,                  // size of that buffer

tylko te dane są mi przydatne... resztę chciałbym pominąć powiedzmy...

1 użytkowników online, w tym zalogowanych: 0, gości: 1