1

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....

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2
 #include <windows.h> HKEY hKey; int buffersize = 1024; char *buffer = new char[buffersize]; RegOpenKeyEx (HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Microsoft SQL Server\\100",NULL,KEY_READ,&hKey); RegQueryValueEx(hKey,"VerSpecificRootDir",NULL,NULL,(LPBYTE) buffer, buffersize); std::cout << buffer; RegCloseKey (hKey); 

1 Comment

should be in "buffer" as a char array. PS: thanks for the fix, JIa3ep!
1

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

Comments

1

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

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.