How can i manipulate Registry
-
HI, How can i manipulate Registry. Any sample by Example. thanx
-
HI, How can i manipulate Registry. Any sample by Example. thanx
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"
-
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"
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"); }
-
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"); }
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;)
-
HI, How can i manipulate Registry. Any sample by Example. thanx