哪个API函数可以读取注册表

来源:百度知道 编辑:UC知道 时间:2024/05/23 15:35:31
顺便把用方法也写写吧。

最简单的一种做法:
1. RegOpenKeyEx(): 打开注册表项
2. RegQueryValueEx(): 取值
3. RegCloseKey(): 关闭注册表项

以下例子从注册表里取IE的cache所在的目录。他在注册表里的表示是:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Cache =(REG_SZ)"......"

源程序如下:

#include <windows.h>

void GetCachePath(BYTE *cachepath, ULONG siz)
{
static BYTE regkey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
static BYTE regitem[] = "Cache";
ULONG dType = REG_SZ;
HKEY hKey;

if (RegOpenKeyEx(HKEY_CURRENT_USER, regkey, 0, KEY_QUERY_VALUE, &hKey)==0) {
RegQueryValueEx(hKey, regitem, 0, &dType, cachepath, &siz);
RegCloseKey(hKey);
}
}

int main()
{
BYTE path[256]="\0";
GetCachePath(path, 256);
printf("IE_Cache: %s