Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can i manipulate Registry

How can i manipulate Registry

Scheduled Pinned Locked Moved C / C++ / MFC
windows-admintutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zeeshan Bilal
    wrote on last edited by
    #1

    HI, How can i manipulate Registry. Any sample by Example. thanx

    Y Y 2 Replies Last reply
    0
    • Z Zeeshan Bilal

      HI, How can i manipulate Registry. Any sample by Example. thanx

      Y Offline
      Y Offline
      Yogesh Kshatriya
      wrote on last edited by
      #2

      Check the following sample function for creating & setting a registry key. You can use APIs RegOpenKeyEx, RegQueryMultipleValues, RegQueryValue defined in winreg.h to read the values from registry keys BOOL CFTPDlg::RegisterFTPProfile(FTPProfile LocalCopyFTPProfile) { BOOL bRetVal; HKEY hkResult; CString strTmp; unsigned char *lpBuf; int n; //Preapre the complete Path Name for selected profile. strTmp = g_strProfileRegPath + CString("\\"); strTmp += (LPCTSTR)LocalCopyFTPProfile.strProfileName ; bRetVal=RegCreateKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)strTmp, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkResult, NULL); if (bRetVal==ERROR_SUCCESS) { n=LocalCopyFTPProfile.strHostAdd.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strHostAdd); bRetVal=RegSetValueEx(hkResult, "HOST_ADD", NULL, REG_SZ, lpBuf, n); free((void *)lpBuf); n=LocalCopyFTPProfile.strLoginID.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strLoginID); bRetVal=RegSetValueEx(hkResult, "LOGINID", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strPassword.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf, (LPCTSTR)LocalCopyFTPProfile.strPassword); bRetVal=RegSetValueEx(hkResult, "PASSWORD", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strHostPath.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strHostPath); bRetVal=RegSetValueEx(hkResult, "HOST_PATH", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strLocalPath.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf , (LPCTSTR)LocalCopyFTPProfile.strLocalPath); bRetVal=RegSetValueEx(hkResult, "LOCAL_PATH", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strSleepTime.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf , (LPCTSTR)LocalCopyFTPProfile.strSleepTime); bRetVal=RegSetValueEx(hkResult, "SLEEP_TIME"

      Z 1 Reply Last reply
      0
      • Y Yogesh Kshatriya

        Check the following sample function for creating & setting a registry key. You can use APIs RegOpenKeyEx, RegQueryMultipleValues, RegQueryValue defined in winreg.h to read the values from registry keys BOOL CFTPDlg::RegisterFTPProfile(FTPProfile LocalCopyFTPProfile) { BOOL bRetVal; HKEY hkResult; CString strTmp; unsigned char *lpBuf; int n; //Preapre the complete Path Name for selected profile. strTmp = g_strProfileRegPath + CString("\\"); strTmp += (LPCTSTR)LocalCopyFTPProfile.strProfileName ; bRetVal=RegCreateKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)strTmp, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkResult, NULL); if (bRetVal==ERROR_SUCCESS) { n=LocalCopyFTPProfile.strHostAdd.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strHostAdd); bRetVal=RegSetValueEx(hkResult, "HOST_ADD", NULL, REG_SZ, lpBuf, n); free((void *)lpBuf); n=LocalCopyFTPProfile.strLoginID.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strLoginID); bRetVal=RegSetValueEx(hkResult, "LOGINID", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strPassword.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf, (LPCTSTR)LocalCopyFTPProfile.strPassword); bRetVal=RegSetValueEx(hkResult, "PASSWORD", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strHostPath.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)LocalCopyFTPProfile.strHostPath); bRetVal=RegSetValueEx(hkResult, "HOST_PATH", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strLocalPath.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf , (LPCTSTR)LocalCopyFTPProfile.strLocalPath); bRetVal=RegSetValueEx(hkResult, "LOCAL_PATH", NULL, REG_SZ, lpBuf, n); free(lpBuf); n=LocalCopyFTPProfile.strSleepTime.GetLength()+1; lpBuf = (unsigned char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf , (LPCTSTR)LocalCopyFTPProfile.strSleepTime); bRetVal=RegSetValueEx(hkResult, "SLEEP_TIME"

        Z Offline
        Z Offline
        Zeeshan Bilal
        wrote on last edited by
        #3

        THe following Code giving the Error that is failing to Open the Key .. n givign mine message box written in else portion.. Keys e created in registry using ur above reply example code plz help abut open n Query the keys BOOL bRetVal; HKEY hkResult; CString strTmp = "Software\\NDT"; char *lpBuf; int n; bRetVal=RegOpenKeyEx( HKEY_LOCAL_MACHINE , (LPCTSTR)strTmp,0,0,&hkResult); if (bRetVal==ERROR_SUCCESS) { CString id = "UserName"; n=id.GetLength()+1; lpBuf = (char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)id); LPSTR str; long j; bRetVal= RegQueryValue(hkResult, lpBuf, str , &j); if (bRetVal==ERROR_SUCCESS) { AfxMessageBox (" Success"); } else { AfxMessageBox (" Not read the key"); } } else { AfxMessageBox (" Not open the key"); }

        Y 1 Reply Last reply
        0
        • Z Zeeshan Bilal

          THe following Code giving the Error that is failing to Open the Key .. n givign mine message box written in else portion.. Keys e created in registry using ur above reply example code plz help abut open n Query the keys BOOL bRetVal; HKEY hkResult; CString strTmp = "Software\\NDT"; char *lpBuf; int n; bRetVal=RegOpenKeyEx( HKEY_LOCAL_MACHINE , (LPCTSTR)strTmp,0,0,&hkResult); if (bRetVal==ERROR_SUCCESS) { CString id = "UserName"; n=id.GetLength()+1; lpBuf = (char *)calloc(n, sizeof(char)); strcpy((char *)lpBuf,(LPCTSTR)id); LPSTR str; long j; bRetVal= RegQueryValue(hkResult, lpBuf, str , &j); if (bRetVal==ERROR_SUCCESS) { AfxMessageBox (" Success"); } else { AfxMessageBox (" Not read the key"); } } else { AfxMessageBox (" Not open the key"); }

          Y Offline
          Y Offline
          Yogesh Kshatriya
          wrote on last edited by
          #4

          Check the help documentation for API RegOpenKeyEx. You need to specify the access level you desire while opening a registry key. You haven't given that. (Check the help documentaion for 4 the para of the API RegOpenKeyEx) That will solve your problem;)

          1 Reply Last reply
          0
          • Z Zeeshan Bilal

            HI, How can i manipulate Registry. Any sample by Example. thanx

            Y Offline
            Y Offline
            Yulianto
            wrote on last edited by
            #5

            there`s plenty of good article here. But I forgot where , may be you can find it at system :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups