久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 Windows 注冊表中讀取值

How to read a value from the Windows registry(如何從 Windows 注冊表中讀取值)
本文介紹了如何從 Windows 注冊表中讀取值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

給定某些注冊表值的鍵(例如 HKEY_LOCAL_MACHINElahlahlahfoo),我該如何:

Given the key for some registry value (e.g. HKEY_LOCAL_MACHINElahlahlahfoo) how can I:

  1. 安全地確定存在這樣的密鑰.
  2. 以編程方式(即使用代碼)獲取其值.

我絕對無意將任何內容寫回注冊表(如果可以的話,在我的職業生涯中).因此,如果我錯誤地寫入注冊表,我們可以跳過關于我體內每個分子以光速爆炸的講座.

I have absolutely no intention of writing anything back to the registry (for the duration of my career if I can help it). So we can skip the lecture about every molecule in my body exploding at the speed of light if I write to the registry incorrectly.

更喜歡 C++ 中的答案,但大多數情況下只需要知道獲得該值的特殊 Windows API 咒語是什么.

Prefer answers in C++, but mostly just need to know what the special Windows API incantation to get at the value is.

推薦答案

這里是一些偽代碼來檢索以下內容:

  1. 如果注冊表項存在
  2. 該注冊表項的默認值是什么
  3. 什么是字符串值
  4. 什么是 DWORD 值

示例代碼:

包含庫依賴:Advapi32.lib

Include the library dependency: Advapi32.lib

HKEY hKey;
LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\Perl", 0, KEY_READ, &hKey);
bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);
std::wstring strValueOfBinDir;
std::wstring strKeyDefaultValue;
GetStringRegKey(hKey, L"BinDir", strValueOfBinDir, L"bad");
GetStringRegKey(hKey, L"", strKeyDefaultValue, L"bad");

LONG GetDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue)
{
    nValue = nDefaultValue;
    DWORD dwBufferSize(sizeof(DWORD));
    DWORD nResult(0);
    LONG nError = ::RegQueryValueExW(hKey,
        strValueName.c_str(),
        0,
        NULL,
        reinterpret_cast<LPBYTE>(&nResult),
        &dwBufferSize);
    if (ERROR_SUCCESS == nError)
    {
        nValue = nResult;
    }
    return nError;
}


LONG GetBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue)
{
    DWORD nDefValue((bDefaultValue) ? 1 : 0);
    DWORD nResult(nDefValue);
    LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue);
    if (ERROR_SUCCESS == nError)
    {
        bValue = (nResult != 0) ? true : false;
    }
    return nError;
}


LONG GetStringRegKey(HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue)
{
    strValue = strDefaultValue;
    WCHAR szBuffer[512];
    DWORD dwBufferSize = sizeof(szBuffer);
    ULONG nError;
    nError = RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, (LPBYTE)szBuffer, &dwBufferSize);
    if (ERROR_SUCCESS == nError)
    {
        strValue = szBuffer;
    }
    return nError;
}

這篇關于如何從 Windows 注冊表中讀取值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進行排序)
Rotating a point about another point (2D)(圍繞另一個點旋轉一個點 (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進)
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進行排序)
主站蜘蛛池模板: 综合一区二区三区 | 在线观看欧美日韩视频 | 欧美日韩在线播放 | 国产精久久 | 男女av在线| 色婷婷综合在线 | 日本中文字幕在线播放 | 国产一区二区三区免费 | 亚洲一区二区国产精品 | 中文字幕av一区二区三区 | 国产欧美精品一区二区 | 成人短视频在线观看 | 成人羞羞国产免费动态 | 中文字幕第一页在线 | 91最新在线 | 超碰av在线 | www.久久久久 | 91精品国产乱码久久久久久 | 久久久久久久av | 久久综合亚洲 | 欧美精品影院 | 黄色av免费看 | 黄色小视频免费观看 | av天天操| 国产欧美在线播放 | 三上悠亚一区二区 | 香蕉视频在线播放 | 户外少妇对白啪啪野战 | 久久亚洲国产精品 | 成人免费视频一区二区 | 黄色大毛片 | 免费日韩视频 | 一级免费毛片 | 久久草视频| 毛茸茸free性熟hd | 中文字幕在线观看第一页 | 五月激情网站 | 18国产免费视频动漫 | 国产草草| 色婷婷一区 | 五月婷婷影院 |