Get Value From Registry Key
-
Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue
-
Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue
RegOpenKeyEx
followed byRegQueryValueEx
followed byRegCloseKey
-
RegOpenKeyEx
followed byRegQueryValueEx
followed byRegCloseKey
Would this correctly output the value located in said key, with the name of "home" into the variable value that I've defined. char* value = NULL; LONG l = 0L; HKEY hKey = {0}; l = RegOpenKeyEx ( HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\Test"), 0, KEY_NOTIFY, &hKey ); if(l == ERROR_SUCCESS) { // The following call will wait until a change is made to the registry key. l = RegQueryValueEx( hKey, TEXT("home"), NULL, NULL, value); RegCloseKey(hKey);
-
Alright lets say I want to get the value from a particular registry key. How would I go about programming that to actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue
Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)
CRegKey l_regKey;
// Open registry location
if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
return;// now as you mentioned you want to retrieve String value
DWORD dwCount=0;// Make a False call to retrieve the data length
l_regKey.QueryValue(NULL,_T("home"),&dwCount);// now allocate string size
LPTSTR pszRetStr=new TCHAR[dwCount+1];// Now retrieve the value from registry
if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
{
MessageBox(pszRetStr,_T("Registry Value"));
}// delete memory allocated to pszRetStr;
if(pszRetStr)
{
delete [] pszRetStr;
pszRetStr=NULL;
}"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)
CRegKey l_regKey;
// Open registry location
if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
return;// now as you mentioned you want to retrieve String value
DWORD dwCount=0;// Make a False call to retrieve the data length
l_regKey.QueryValue(NULL,_T("home"),&dwCount);// now allocate string size
LPTSTR pszRetStr=new TCHAR[dwCount+1];// Now retrieve the value from registry
if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
{
MessageBox(pszRetStr,_T("Registry Value"));
}// delete memory allocated to pszRetStr;
if(pszRetStr)
{
delete [] pszRetStr;
pszRetStr=NULL;
}"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
Thanks alot for the help, I was able to implement your code perfectly Alok. Again much appreciated.
-
Thanks alot for the help, I was able to implement your code perfectly Alok. Again much appreciated.
Matthew Devine wrote: Thanks alot for the help, Mention Not Please :)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
Matthew Devine wrote: I want to get the value from a particular registry key Use CRegKey defined in atlbase.h Matthew Devine wrote: actually accomplish this feat. Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Test Name: home value: testvalue here is the small piece of code to accomplish that :)
CRegKey l_regKey;
// Open registry location
if( l_regKey.Open(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\Test")!=ERROR_SUCCESS))
return;// now as you mentioned you want to retrieve String value
DWORD dwCount=0;// Make a False call to retrieve the data length
l_regKey.QueryValue(NULL,_T("home"),&dwCount);// now allocate string size
LPTSTR pszRetStr=new TCHAR[dwCount+1];// Now retrieve the value from registry
if(l_regKey.QueryValue(pszRetStr,_T("home"),&dwCount)==ERROR_SUCCESS)
{
MessageBox(pszRetStr,_T("Registry Value"));
}// delete memory allocated to pszRetStr;
if(pszRetStr)
{
delete [] pszRetStr;
pszRetStr=NULL;
}"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
I was trying to now look up the registry key value of ProxyEnable: This is located in "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", I was trying to edit your code to work with the fact that this is a DWORD. But I can't seem to get it to work, what I want to do is query the value of that key. After I have the value I just want to write a simple if-statement that will execute ProxyOn() method if the Proxy is seen as being enabled and a ProxyOff() method if the proxy is disabled. Any assistance would be greatly appreciated.