tags:

views:

241

answers:

5

Hi

Ineed to open this key" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\"

and get the "VerSpecificRootDir" value using c++ ....How can i do this

I have no knowledge abt it can any one help me in this regard..

After Getting All The Support I did it as

 unsigned long type=REG_SZ, size=1024;
 char res[1024]="";
 HKEY hk;

long n = RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\Microsoft\\Microsoft SQL Server\\100"),
                  0,KEY_QUERY_VALUE, &hk );
if ( n == ERROR_SUCCESS ) 
{
    printf("OK \n");
 RegQueryValueEx(hk,L"VerSpecificRootDir",NULL,&type,(LPBYTE)&res[0],&size);
 RegCloseKey(hk);

}

But in this i am not getting the value of "VerSpecificDirectory" what i have missed let me know?? what is wrong in this code....

+1  A: 

Hi,

I currently only know how to do that by using the Qt framework:

QSettings settings("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\");
QString dir = settings.value("VerSpecificRootDir");

Qt is free and allows you to use simple and very good documented c++ APIs instead of the mixed and up Windows APIs. Sorry - that sounds for advertising... but I formerly struggled with the very bad designed Windows API and than found Qt, which allows me to develop faster and (a cool benefit) for multiple platforms without having to adapt my code.

Regards, Chris

3DH
+2  A: 

You can use the Windows function SHRegGetValue like this:

TCHAR buffer[260];
DWORD bufferSize = sizeof(buffer);
SHRegGetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SQL Server\\100", "VerSpecificRootDir", SRRF_RT_REG_SZ, NULL, buffer, &bufferSize);

After calling the function, buffer will contain a null-terminated string of the directory. Might want to check the return value for errors too.

Jordan Miner
+1  A: 
Zed
How can i get the value that is contained by VerSpecificRootDir in this...
Cute
should be in "buffer" as a char array.PS: thanks for the fix, JIa3ep!
Zed
+1  A: 

You can sure use ATL::CRegKey. It has all the functionality you need.

http://msdn.microsoft.com/en-us/library/xka57xy4(VS.80).aspx

Ivan Zlatanov
+1  A: 

Registry API was available (for ~15 years) from Windows 95 onwards. It's all well documented on MSDN ; and if you care to Google so many examples.

Indeera