CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old June 10th, 2002, 01:16 PM
    shethashish_a shethashish_a is offline
    Member
     
    Join Date: May 2002
    Location: Hyderabad
    Posts: 76
    shethashish_a is an unknown quantity at this point (<10)
    Exclamation how to access registry

    Hi,
    I am a VB developer and I want to know how to access registry values in windows? how to write to the registry?
    I want to access name of some application's installed on the user's pc so how to do that using registry? Or any other way to do that?

    Also while installing our application how can we make the user to enter his or his company name and how can we access that name in our application?

    Can any body help me?

    Thanks,
    Ashish
    __________________
    Ashish Sheth
    Reply With Quote
      #2    
    Old June 10th, 2002, 01:39 PM
    adnankhan adnankhan is offline
    Junior Member
     
    Join Date: Jun 2002
    Location: Milwaukee, WI
    Posts: 7
    adnankhan is an unknown quantity at this point (<10)
    Look in MSDN for help on the following WIN32 APIs.

    RegOpenKey, RegCloseKey etc ...

    Here is some code to help you out ...

    // QueryKey - enumerates the subkeys of a given key and the associated
    // values and then copies the information about the keys and values
    // into a pair of edit controls and list boxes.
    // hDlg - dialog box that contains the edit controls and list boxes
    // hKey - key whose subkeys and values are to be enumerated

    VOID QueryKey(HWND hDlg, 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, j;
    DWORD retCode, retValue;

    CHAR achValue[MAX_VALUE_NAME];
    DWORD cchValue = MAX_VALUE_NAME;
    CHAR achBuff[80];

    // Get the class name and the value count.
    RegQueryInfoKey(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

    SetDlgItemText(hDlg, IDE_CLASS, achClass);
    SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE);

    SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
    LB_ADDSTRING, 0, (LONG) "..");

    // Enumerate the child keys, until RegEnumKeyEx fails. Then
    // get the name of each child key and copy it into the list box.

    SetCursor(LoadCursor(NULL, IDC_WAIT));
    for (i = 0, retCode = ERROR_SUCCESS;
    retCode == ERROR_SUCCESS; i++)
    {
    retCode = RegEnumKeyEx(hKey,
    i,
    achKey,
    MAX_PATH,
    NULL,
    NULL,
    NULL,
    &ftLastWriteTime);
    if (retCode == (DWORD)ERROR_SUCCESS)
    {
    SendMessage(GetDlgItem(hDlg, IDL_LISTBOX),
    LB_ADDSTRING, 0, (LONG) achKey);
    }
    }
    SetCursor(LoadCursor (NULL, IDC_ARROW));

    // Enumerate the key values.
    SetCursor(LoadCursor(NULL, IDC_WAIT));

    if (cValues)
    {
    for (j = 0, retValue = ERROR_SUCCESS;
    j < cValues; j++)
    {
    cchValue = MAX_VALUE_NAME;
    achValue[0] = '\0';
    retValue = RegEnumValue(hKey, j, achValue,
    &cchValue,
    NULL,
    NULL, // &dwType,
    NULL, // &bData,
    NULL); // &bcData

    if (retValue != (DWORD) ERROR_SUCCESS &&
    retValue != ERROR_INSUFFICIENT_BUFFER)
    {
    wsprintf (achBuff,
    "Line:%d 0 based index = %d, retValue = %d, "
    "ValueLen = %d",
    __LINE__, j, retValue, cchValue);
    MessageBox (hDlg, achBuff, "Debug", MB_OK);
    }

    achBuff[0] = '\0';

    // Add each value to a list box.
    if (!lstrlen(achValue))
    lstrcpy(achValue, "<NO NAME>");
    wsprintf(achBuff, "%d) %s ", j, achValue);
    SendMessage(GetDlgItem(hDlg,IDL_LISTBOX2),
    LB_ADDSTRING, 0, (LONG) achBuff);
    }

    SetCursor(LoadCursor(NULL, IDC_ARROW));
    }


    Hope this helps

    Take it easy
    AK
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:24 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009