Reputation: 14011
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....
Upvotes: 1
Views: 4468
Reputation: 2054
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.
Upvotes: 3
Reputation: 8851
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.
Upvotes: 0
Reputation: 5226
You can sure use ATL::CRegKey
. It has all the functionality you need.
http://msdn.microsoft.com/en-us/library/xka57xy4(VS.80).aspx
Upvotes: 1
Reputation: 57648
#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);
Upvotes: 2
Reputation: 1471
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
Upvotes: 1