您好,登錄后才能下訂單哦!
MFC中的CRegKey類,是注冊表操作類,用法如下:
(1)創建鍵函數:
CRegKey key; long ret = key.Create(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Scale3DC"), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ | KEY_WOW64_64KEY); key.Close(); //在WIN10下須管理員權限
(2)打開鍵并寫入值:
int iMaxNumber = 100; key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\TheSoft")); key.SetStringValue(_T("Password"), _T("123")); key.SetDWORDValue(_T("count"),iMaxNumber); key.Close(); long ret1 = key.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Scale3DC"), KEY_SET_VALUE | KEY_WOW64_64KEY); if (ret1 == ERROR_SUCCESS) { long ret =key.SetStringValue(_T("DisplayName"), _T("Scale3DC管理系統")); key.SetStringValue(_T("UninstallString"), GetApplicationPath() + _T("Uninstall.exe")); key.SetStringValue(_T("DisplayIcon"), GetApplicationPath() + _T("Scale3DC.exe")); key.SetStringValue(_T("DisplayVersion"), _T("v2018")); key.SetStringValue(_T("URLInfoAbout"), _T("http://www.zync.com")); key.SetStringValue(_T("Publisher"), _T("3DC科技有限公司")); } key.Close();
(3)讀取注冊表的信息:
DWORD dwNum; BOOL bOpenReg = key.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\TheSoft")); //或者key.QueryValue(dwNum,_T("count")); key.QueryDWORDValue(_T("count"),dwNum);
(4)刪除注冊的信息:
key.DeleteValue(_T("count"));
用API刪除注冊表中的鍵
VOID CScale3DCControl::DeleteMainKey() { HKEY hKey; DWORD result; result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"), NULL, KEY_SET_VALUE|KEY_WOW64_64KEY, &hKey);//讀取注冊表串口信息 if (ERROR_SUCCESS == result) { long lResult = ::RegDeleteKey(hKey, _T("Scale3DC")); if (lResult == ERROR_SUCCESS) { AfxMessageBox(_T("ok1")); } } else { ::MessageBox(0, _T("DELETE ERROR!"), _T("Error"), 0); } RegCloseKey(hKey); }
Win10系統須管理員權限
(5)讀注冊表
HKEY hKey; DWORD result; DWORD dwType; DWORD sl = 255; TCHAR sz[255]; //存儲鍵值 result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\abc"), NULL, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey); if (ERROR_SUCCESS == result) { result = RegQueryValueEx(hKey, _T("DisplayIcon"), NULL, &dwType, (LPBYTE)sz, &sl); if (result == ERROR_SUCCESS) { RegCloseKey(hKey); return sz; } } else { ::MessageBox(0, _T("DELETE ERROR!"), _T("Error"), 0); } RegCloseKey(hKey);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。