I have originally created the SOFTWARE\\Testing key a few days ago and I just tried adding another value called TDate to this key and got an "Access denied" message when I execute the RegSetValueEx function. Does anybody know why I'm getting this "access denied" error message?
EDIT: Found my mistake.. RegOpenKeyEx should be KEY_ALL_ACCESS NOT KEY_QUERY_VALUE. I guess I'm a little brain dead.
Code:DWORD lpdwDisp; HRESULT hRes; HKEY hKey; char szTDate[40] = {0}; int iDatasize; char szTemp[120] = {0}; char szRegistryKey[128] = "SOFTWARE\\Testing"; if(RegOpenKeyEx (HKEY_CURRENT_USER, szRegistryKey, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { iDatasize = sizeof ( szTDate); if(RegQueryValueEx(hKey, "TDate", NULL, NULL, (unsigned char *)& szTDate, (unsigned long *)&iDatasize) != ERROR_SUCCESS) { printf("Query failed, create the value\n"); strcpy(szTDate, "11082005"); hRes = RegSetValueEx(hKey, "TDate", 0, REG_SZ,(LPBYTE)szTDate,(DWORD) strlen(szTDate)+1); if( ERROR_SUCCESS != hRes) { FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL , hRes, 0, szTemp, 80 , NULL); printf("%s\n",szTemp); } } }



LinkBack URL
About LinkBacks


