CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2003
    Location
    Azerbaijan
    Posts
    74

    Help with registry key value.

    How to determine using WINAPI registry means whether the registry key exists???

  2. #2
    Join Date
    Sep 2002
    Posts
    924
    Do you want to create the key if it does not exist?
    If so, then you could use RegCreateKeyEx. It will create the key if it does not exist, and it will open the key if it does exist. Then you could check the value of lpdwDisposition to see whether it created the key or opened it.

  3. #3
    Join Date
    Sep 2002
    Posts
    924
    Here is an example of doing it using RegCreateKeyEx.
    Code:
    HKEY phkResult;
    DWORD lpdwDisposition;
    
    RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\My Programs\\My Program"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &phkResult, &lpdwDisposition);
    
    if (lpdwDisposition == REG_CREATED_NEW_KEY) // key did not exist
    {
         // set default registry values for your program 
    }
    
    // Read in your values
    One way of doing it...

  4. #4
    Join Date
    Jun 2003
    Location
    Azerbaijan
    Posts
    74
    No, I want to query it's value, but the returned result is ERROR_FILE_NOT_FOUND.
    Does this returned result mean that the key doesn't exist in this context???

  5. #5
    Join Date
    Sep 2002
    Posts
    924
    Yes, you would receive that error as returned by RegOpenKeyEx if the key did not exist.

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    Is that what you were looking for, or are you having problems opening a key that you know exits (if so, posting the related code would help)?

  7. #7
    Join Date
    Jun 2003
    Location
    Azerbaijan
    Posts
    74
    Yes, thanx. I just wanted to be sure in the meaning of the return code.
    But the function that I am using is RegQueryValueEx, but I think it doesn't matter in this case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured