zoukankan      html  css  js  c++  java
  • 读取注册表

    #include <iostream>
    #include <assert.h>
    #include <windows.h>
    #include <tchar.h>
    #include <conio.h>
    #include <stdio.h>
    using namespace std;
    
    void wcharTochar(const wchar_t* wchar, char* chr, int length)
    {
        WideCharToMultiByte(CP_ACP, 0, wchar, -1,
            chr, length, NULL, NULL);
    }
    
    bool OpenRegKey(HKEY& hRetKey)
    {
        LPCWSTR sw = _T("SOFTWARE\Classes\FeikuaBrowserFile.myp\DefaultIcon");
        wprintf(L"SW is %s
    ", sw);
        if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, sw, &hRetKey))
        {
            return true;
        }
        printf("OpenRegKey return is false!
    ");
        return false;
    }
    
    bool QueryRegKey(LPCWSTR strSubKey, LPCWSTR strValueName, char* strValue, int length)//这里是传4个参数
    {
        DWORD dwType = REG_SZ;//定义数据类型
        DWORD dwLen = MAX_PATH;
    
        wchar_t data[MAX_PATH];
        HKEY hKey;
        HKEY hSubKey;
        if (OpenRegKey(hKey))
        {
            if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, strSubKey, &hSubKey))
            {
                TCHAR buf[256] = { 0 };
    
                if (ERROR_SUCCESS == RegQueryValueEx(hSubKey, strValueName, 0, &dwType, (LPBYTE)data, &dwLen))
                {
                    wcharTochar(data, strValue, length);
                    wprintf(L"data = %s,len= %d
    ", data, strlen((const char*)data));
                    RegCloseKey(hKey); //关闭注册表
                    return true;
                }
            }
            RegCloseKey(hKey); //关闭注册表
        }
    
        return false;
    }
    int main()
    { 
        HKEY  hKey = NULL;
        string result;
        LPCWSTR strSubKey = _T("SOFTWARE\Classes\FeikuaBrowserFile.myp\DefaultIcon");
        LPCWSTR strValueName = _T("");
        char strValue[256];
        int length = 256;
        bool status = QueryRegKey(strSubKey, strValueName, strValue, length);
        printf("status is %d
    ", status);
        printf("result is %s
    ", strValue);
        return 0;
    }

    默认值按空串处理

  • 相关阅读:
    QTP自学攻略
    自动检查页面链接是否有效
    使用Loadrunner进行接口测试
    缺陷管理方案
    python读取文本、配对、插入数据脚本
    QTP 中对象操作
    python学习笔记(三)--条件语句
    npm WARN uninstall not installed in /Users/hrt0kmt/node_modules: "xxx"
    appium mac 下 安装及踩坑
    homebrew -v 或homebrew -doctor报错请检查 .bash_profile是否有误
  • 原文地址:https://www.cnblogs.com/Galesaur-wcy/p/15076551.html
Copyright © 2011-2022 走看看