0% found this document useful (0 votes)
59 views3 pages

CS609 Assignment 2

The document provides instructions for a C/C++ program assignment to: 1. Open a duplicate of the predefined HKEY_CURRENT_USER_LOCAL_SETTINGS registry key without options and with subkey enumeration access. 2. Use RegEnumKeyEx() to list the subkeys of the duplicated key, incrementing the index on each call. 3. Check for successful duplication and enumeration completion.

Uploaded by

Adil sajjad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views3 pages

CS609 Assignment 2

The document provides instructions for a C/C++ program assignment to: 1. Open a duplicate of the predefined HKEY_CURRENT_USER_LOCAL_SETTINGS registry key without options and with subkey enumeration access. 2. Use RegEnumKeyEx() to list the subkeys of the duplicated key, incrementing the index on each call. 3. Check for successful duplication and enumeration completion.

Uploaded by

Adil sajjad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS609 Assignment 2

Question:
Write a C/C++ program that will open a duplicated new Registry Key using

RegOpenKeyEx() function. After opening, enlist all subkeys of duplicated key using

regEnumKeyEx() function.

Detailed Instructions:

 Assume that the currently open key is the predefined key:

HKEY_CURRENT_USER_LOCAL_SETTINGS. You have to make a duplicate of this

key by using RegOpenKeyEx() function.

 The DWORD ulOptions parameter in RegOpenKeyEx() function should be zero.

 Take KEY_ENUMERATE_SUBKEY as the access mask for the duplicated key.

 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.

 You may take last three parameters of RegEnumKey() function as NULL.

Solution:-

#include <stdlib.h>
#include <Windows.h>

int main()
{
constintMax_Key_Length = 255;
LONG lRValue;
DWORD dwIndex;
DWORD dwKeyNameLength = Max_Key_Length;
HKEY hOpenKey;

lRValue = RegOpenKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, KEY_READ,


&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");
}

lReturnValue = RegCreateKeyEx(hKey, tszNewkeyName, 0, NULL,


REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubkey, &dwDisposition);

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;
}

You might also like