Access denied on adding another registry value

This is a discussion on Access denied on adding another registry value within the Windows Programming forums, part of the Platform Specific Boards category; I have originally created the SOFTWARE\Testing key a few days ago and I just tried adding another value called TDate ...

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

    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, 02: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, 09:49 AM
  4. Windows cannot update registry
    By lightatdawn in forum Tech Board
    Replies: 12
    Last Post: 08-26-2004, 07:56 AM
  5. Registry Access
    By ExDigit in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2002, 04:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21