如何打开注册表并获得在c ++中的具体值 [英] How to open the registry and get the specific value in c++

查看:206
本文介绍了如何打开注册表并获得在c ++中的具体值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要打开此密钥HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\

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

并使用VerSpecificRootDir值c ++ ....我如何做这个

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

我不知道abt它可以帮助我在这方面..

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

获取所有的支持我做了

 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);

}

但是在这里我没有得到VerSpecificDirectory 我错过了什么让我知道?

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

推荐答案

可以使用Windows函数 SHRegGetValue 像这样: / p>

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);

调用函数后, buffer 目录的以null结尾的字符串。您也可以检查错误的返回值。

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

这篇关于如何打开注册表并获得在c ++中的具体值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆