Greetings lvdude,
Doing this is not hard. There is a simple approach to this.
Understanding that you are talking about Windows, hence the "Registry", it is not hard to check for a key and its existance.
I just wrote an example of how to query a registry key. It may help gear you in the right direction:
#include <windows.h>
#include <stdio.h>
int checkKey(HKEY tree, const char *folder, char *key) {
long lRet;
HKEY hKey;
char temp[150];
DWORD dwBufLen;
// Open location
lRet = RegOpenKeyEx( tree, folder, 0, KEY_QUERY_VALUE, &hKey );
if (lRet != ERROR_SUCCESS)
return 0;
// Get key
dwBufLen = sizeof(temp);
lRet = RegQueryValueEx( hKey, key, NULL, NULL, (BYTE*)&temp, &dwBufLen );
if (lRet != ERROR_SUCCESS)
return 0;
printf("Key value: %s\n", temp);
// Close key
lRet = RegCloseKey( hKey );
if (lRet != ERROR_SUCCESS)
return 0;
// Got this far, then key exists
return 1;
}
int main() {
printf("Checking for key: HKEY_CURRENT_USER -> Control Panel -> Desktop -> Wallpaper\n");
if (checkKey(HKEY_CURRENT_USER, "Control Panel\\Desktop", "Wallpaper"))
printf("Key Exists.\n");
else
printf("Key Does Not Exist.\n");
return 0;
}
Hope this helps.RegQueryValueEx()
The RegQueryValueEx function retrieves the type and data for a specified value name associated with an open registry key.
LONG RegQueryValueEx(
HKEY hKey, // handle of key to query
LPTSTR lpValueName, // address of name of value to query
LPDWORD lpReserved, // reserved
LPDWORD lpType, // address of buffer for value type
LPBYTE lpData, // address of data buffer
LPDWORD lpcbData // address of data buffer size
);
Or learn more about it here .
There are other functions, though simply doing an MSDN search may pull up further documentation on such functions within the windows header file.
I hope this does help, and if you have any further questions please feel free to ask.
- Stack Overflow