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
¤tSubLen, // 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);
}