Spring 2022 - CS609 - 2 - MC200402621
Spring 2022 - CS609 - 2 - MC200402621
Spring 2022 - CS609 - 2 - MC200402621
Assignment No. 02
Objectives:
Detailed Instructions:
RegOpenKeyEx() function.
In RegEnumKeyEx() function, the value of dwIndex should be zero on first call and should be
incremented on each subsequent calls.
Create a character buffer which will store the name of the sub keys (NULL terminated name). Buffer size
will be 255.
Solution:-
#include <stdlib.h>
#include <Windows.h>
int main()
{
constintMax_Key_Length = 255;
LONG lRValue;
DWORD dwIndex;
DWORD dwKeyNameLength = Max_Key_Length;
HKEY hOpenKey;
if (lRValue == ERROR_SUCCESS) {
printf("Opened the subkey successfully.\n\n");
}
else {
printf("Error encountered.\n");
exit(EXIT_FAILURE);
}
lRValue = RegEnumKeyEx(hOpenKey, dwIndex, keyName, &dwKeyNameLength, 0, NULL, NULL,
&structFT);
while (lRValue == ERROR_SUCCESS) {
_tprintf(_T("%s\n"), keyName);
dwKeyNameLength = Max_Key_Length;
lRValue = RegEnumKeyEx(hOpenKey, ++dwIndex, keyName, &dwKeyNameLength, 0, NULL, NULL,
&structFT);
}
if (lRValue == ERROR_NO_MORE_ITEMS) {
printf("\nSubkeys all enumerated successfully.\n\n");
}
if (lReturnValue == ERROR_SUCCESS) {
printf("Created/opened new subkey.\n");
if (dwDisposition == REG_OPENED_EXISTING_KEY) {
_tprintf(_T("%s Already Existing File is opening"), tszNewkeyName);
}
else {
_tprintf(_T("%s New file is Created and Now opening\n"), tszNewkeyName);
}
HKEY hTheKey;
longlongintllRValue;
llRValue = RegOpenKeyEx(
HKEY_CURRENT_USER,
NULL,
0,
KEY_QUERY_VALUE,
&hTheKey
);
if (llRValue == ERROR_SUCCESS) {
printf("Duplicate registry key created!\n");
}
else {
printf("Duplicate registry key not created!\n");
}
RegCloseKey(hKey);
return 0;
}
---BEST OF LUCK---