久久久久久久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 排序功能對列表進行排序)
主站蜘蛛池模板: 成年人在线 | 久久高清 | 久久久久久久久久久久久9999 | 一级毛片免费完整视频 | 欧美高清一级片 | 男人午夜视频 | 中文字幕免费中文 | 国产精品久久久久一区二区 | 精品国产伦一区二区三区观看方式 | 黄色片在线网站 | 日韩成年人视频在线 | 中文字幕乱码视频32 | 久久一| 国产成人精品免费 | 成人午夜| 高清黄色网址 | 欧美亚洲国产一区二区三区 | 99re6在线视频精品免费 | 一本一道久久a久久精品综合 | 久久婷婷国产香蕉 | 色婷婷综合久久久中字幕精品久久 | 精品美女 | 东京av男人的天堂 | 久久久久免费精品国产小说色大师 | 国产精品美女久久久久久久网站 | 日韩视频福利 | 色视频网站免费 | 午夜影院在线观看视频 | 蜜桃臀av一区二区三区 | 三级视频在线观看 | 日日骚网 | a国产视频 | 亚洲成人自拍 | 久久久男人的天堂 | 日韩精品免费看 | 99国产精品一区二区三区 | 欧美一级做a爰片免费视频 国产美女特级嫩嫩嫩bbb片 | 亚洲成人一区二区在线 | 伊人免费在线观看高清 | 久久久av | 亚洲精品一区二区在线观看 |