• 注册表写入


    #include <iostream>  
    #include <algorithm>  
    #include <cmath>  
    #include <vector>  
    #include <string>  
    #include <cstring>
    #include <atlbase.h>
    #include <Windows.h>
    #include <atlstr.h>
    #pragma warning(disable:4996)  
    using namespace std;
    
    bool write_reg_sz(LPCTSTR SubKey, LPCTSTR Key, CString Value)
    {
        HKEY hkey;
        HKEY hTempKey;
        DWORD nLength = (Value.GetLength() + 1) * sizeof(TCHAR);    // 定义数据长度
        LPBYTE lpbName = new BYTE[nLength * sizeof(TCHAR)];    // 有可能是 Ansi 或 Unicode
        memcpy(lpbName, (void*)(LPCTSTR)Value, (Value.GetLength() + 1) * sizeof(TCHAR));
        LPCTSTR data_set = _T("");
        if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CLASSES_ROOT, data_set, 0, KEY_SET_VALUE, &hkey))
        {
            if (ERROR_SUCCESS == ::RegCreateKey(hkey, SubKey, &hTempKey))
            {
                if (ERROR_SUCCESS != ::RegSetValueEx(hTempKey, Key, 0, REG_SZ, lpbName, nLength))
                {
                    cout << "写入错误" << endl;
                }
            }
            ::RegCloseKey(hTempKey);
        }
        ::RegCloseKey(hkey);
        return true;
    }
    
    int main()
    {   
        write_reg_sz(_T("hahah"), _T("URL Protocol"),_T(""));
        write_reg_sz(_T("hahah"), _T(""), _T("hahah Protocol"));
        write_reg_sz(_T("hahah\DefaultIcon"), _T(""), _T("XXXX路径"));
        write_reg_sz(_T("hahah\shell"), _T(""), _T(""));
        write_reg_sz(_T("hahah\shell\open"), _T(""), _T(""));
        write_reg_sz(_T("hahah\shell\open\command"), _T(""), _T("XXXXXX路径 %1"));
        system("pause");
        return 0;
    }
    
  • 相关阅读:
    List<T>的使用
    onclientclick和onclick区别
    IOS学习资料
    DataTable排序的一般方法
    jquery特效
    交叉表、行列转换和交叉查询经典
    sql截取查询
    DelPhi学习网站
    EasyDarwin开源云平台接入海康威视EasyCamera摄像机之快照获取与上传
    EasyDarwin开源云平台接入海康威视EasyCamera摄像机之快照获取与上传
  • 原文地址:https://www.cnblogs.com/Galesaur-wcy/p/15141344.html
Copyright © 2020-2023  润新知