VC 中對登錄檔的操作

2021-04-23 21:19:30 字數 1222 閱讀 4142

這裡只是對登錄檔的幾個api函式的使用簡介。在mfc中,你可以使用cregkey類操作登錄檔,關於cregkey類在這裡就不做介紹了,可以參考msdn。

以下**實現了在hkey_local_machine的software下開啟myprogram鍵,如果myprogram不存在,則建立之,存在則進行查詢

hkey hkey;

hkey hkeyresult;

lpctstr lpszsubkey;

lpctstr lpszvaluename;

long ret;

dword dwtype;

dword dwsize;

hkey = hkey_local_machine;

lpszsubkey = _t("software//myprogram");

ret = regopenkeyex(

hkey,                                      // 根鍵

lpszsubkey,                           // 子鍵

0,                                             // 必須為0

key_all_access,            // 訪問許可權

&hkeyresult);                     // 儲存開啟的鍵的控制代碼

if (ret != error_success)       // 若開啟失敗,則進行建立

else

}else // 如開啟成功,則進行查詢

lpszvaluename = _t("date");

dwtype = reg_sz;

dwsize = max_path;

byte *pbytesubkey = new byte[max_path];

zeromemory(pbytesubkey, max_path);

ret = regqueryvalueex(

hkeyresult,

lpszvaluename,

0,&dwtype,

pbytesubkey,

&dwsize);

regclosekey(hkeyresult);

delete pbytesubkey;

pbytesubkey = null;

if (ret != error_success)

}

VC操作登錄檔

1.vc讀取登錄檔資訊 hkey hkey lpctstr data set software yeete s long ret5 regopenkeyex hkey local machine,data set,0,key write key read,hkey long ret0 regdele...

VC操作登錄檔

vc操作登錄檔 邵盛松 2010 3 2 新增標頭檔案atlbase.h 寫入登錄檔鍵值 以設定字串值為例 cstring strpath t c name.exe cregkey key if key.create hkey local machine,t software microsoft w...

VC 登錄檔操作

獲取登錄檔值 hkey hkey lpctstr data set software internet long ret0 regopenkeyex hkey local machine,data set,0,key all access,hkey lpbyte lpa new byte 500 d...