Registry handling API’s (RegOpenKeyEx()/RegCreateKeyEx()/ RegSetValueEx()/RegQueryValueEx())

LONG lResult;
HKEY hKey, hSubKey;

//Opening registry key.
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(“Software”), 0, KEY_READ, &hKey);
if(lResult != ERROR_SUCCESS)
return lResult;

//Creating new key

lResult = RegCreateKeyEx(hKey, REG_COMPANY_NAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, NULL);
if(lResult != ERROR_SUCCESS)
return lResult;

RegCloseKey(hKey);
hKey = hSubKey;
lResult = RegCreateKeyEx(hKey, REG_PRODUCT_NAME, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, NULL);
if(lResult != ERROR_SUCCESS)
return lResult;

//Creating new value under the created key.

lResult = RegSetValueEx(hKey, KEY_COUNT, 0, REG_SZ,(PBYTE)”0″, 1);
if(lResult != ERROR_SUCCESS)
return lResult;

//Reading existing value

BYTE lpszData[1024];
dwSize = sizeof(lpszData);
lResult = RegQueryValueEx(hKey, KEY_HOME_PATH, NULL, &dwType, (PBYTE)lpszData, &dwSize);
if(lResult != ERROR_SUCCESS)
return lResult;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: