CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    66

    Registry problem

    Hello. I need some code that will allow me to access a known path through the registry and read an unknown value name and value, of which I know the index. In other words, I need to be able to read the default value in a folder to check for present software...The default is not always called "default", in German it's "Standard", in French, ??. Can anyone help me with this?


  2. #2
    Join Date
    Jun 1999
    Posts
    5

    Re: Registry problem

    Here is some sample code which uses RegQueryInfoKey
    and loops through the sub keys. You could look via a case statement for whatever values you want and do as you see fit.

    void CCFISetupDlg::QueryKey(HANDLE hKey)
    {

    CHAR achKey[MAX_PATH];
    CHAR achClass[MAX_PATH] = ""; // buffer for class name
    DWORD cchClassName = MAX_PATH; // length of class string
    DWORD cSubKeys; // number of subkeys
    DWORD cbMaxSubKey; // longest subkey size
    DWORD cchMaxClass; // longest class string
    DWORD cValues; // number of values for key
    DWORD cchMaxValue; // longest value name
    DWORD cbMaxValueData; // longest value data
    DWORD cbSecurityDescriptor; // size of security descriptor
    FILETIME ftLastWriteTime; // last write time

    DWORD i;
    DWORD retCode;

    DWORD cchValue = _MAX_FNAME;

    // Get the class name and the value count.
    RegQueryInfoKey((struct HKEY__ *)hKey, // key handle
    achClass, // buffer for class name
    &cchClassName, // length of class string
    NULL, // reserved
    &cSubKeys, // number of subkeys
    &cbMaxSubKey, // longest subkey size
    &cchMaxClass, // longest class string
    &cValues, // number of values for this key
    &cchMaxValue, // longest value name
    &cbMaxValueData, // longest value data
    &cbSecurityDescriptor, // security descriptor
    &ftLastWriteTime); // last write time

    // Enumerate the child keys, looping until RegEnumKey fails. Then
    // get the name of each child key and copy it into the list box.
    for (
    i = 0, retCode = ERROR_SUCCESS;
    retCode == ERROR_SUCCESS;
    i++
    )
    {
    retCode = RegEnumKey((struct HKEY__ *)hKey, i, achKey, MAX_PATH);
    if (retCode == (DWORD)ERROR_SUCCESS)
    {
    //valid key
    struct HKEY__ * hNextKey;
    int RegOpenRet;

    //search for our value
    if (strcmp(achKey,"TEST") == 0 )
    {
    switch (1)
    {
    case 1:
    RegOpenRet = RegOpenKeyEx( (struct HKEY__ *)hKey,"Microsoft",0,KEY_READ,&hNextKey);
    if (RegOpenRet != (DWORD)ERROR_SUCCESS)
    printf("help");
    QueryKey(hNextKey);
    }
    }
    }
    }

    }





  3. #3
    Join Date
    May 1999
    Posts
    66

    Re: Registry problem

    Hey, thanks for the response...We actually figured out yesterday that if you pass a NULL as the value name, it returns the default value, which is what we need...I appreciate your help though...


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