Thread: Access denied on adding another registry value

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058

    Access denied on adding another registry value

    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);
            }
          }
        }
    Last edited by BobS0327; 01-09-2006 at 08:53 PM. Reason: Correct the code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Registry, Regedit
    By franse in forum C++ Programming
    Replies: 21
    Last Post: 01-29-2009, 09:57 AM
  2. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  3. ww hosting and SSH access
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-07-2005, 08:49 AM
  4. Windows cannot update registry
    By lightatdawn in forum Tech Board
    Replies: 12
    Last Post: 08-26-2004, 06:56 AM
  5. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM