zoukankan      html  css  js  c++  java
  • 验证reg注册表的操作

    // wRegKey
    class wRegKey
    {
    // Operations
    public:
    BOOL Create(HKEY hKeyParent, LPCTSTR lpszKeyName
    , LPTSTR lpszClass = REG_NONE
    , DWORD dwOptions = REG_OPTION_NON_VOLATILE
    , REGSAM samDesired = KEY_ALL_ACCESS
    , LPSECURITY_ATTRIBUTES lpSecAttr = NULL
    , LPDWORD lpdwDisposition = NULL);
    LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired = KEY_ALL_ACCESS);
    void CloseKey();
    public:
    DWORD QueryValue(LPCTSTR lpszValueName, DWORD dwDefaultValue);
    chString QueryValue(LPCTSTR lpszValueName, LPTSTR szDefaultValue);
    BOOL SetValue(LPCTSTR lpszValueName, DWORD dwValue);
    BOOL SetValue(LPCTSTR lpszValueName, LPCTSTR lpszValue);
    BOOL DeleteValue(LPCTSTR lpszValueName);
    BOOL DeleteSubKey(LPCTSTR lpszSubKeyName);
    public:
    // static
    static BOOL SetKeyValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName, LPCTSTR lpszDefaultValue);
    static BOOL SetKeyValue(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName, DWORD dwDefaultValue);
    static BOOL DeleteKey(HKEY hKeyParent, LPCTSTR lpszKeyName);
    static BOOL IsKeyExist(HKEY hKeyParent, LPCTSTR lpszKeyName);
    static BOOL IsValueExist(HKEY hKeyParent, LPCTSTR lpszKeyName, LPCTSTR lpszValueName);
    protected:
    operator HKEY() const;
    HKEY Detach();
    void Attach(HKEY hKey);
    public:
    wRegKey();
    wRegKey(LPCTSTR strKeyName, HKEY hParentKey = HKEY_LOCAL_MACHINE);
    ~wRegKey();
    private:
    // Attributes
    HKEY m_hKey;
    };

    wRegKey key;
    /*if(!key.Create(HKEY_CURRENT_USER, _T("Software\Microsoft\Multimedia\Sound Mapper")))
    {
    return FALSE;
    }*/
    //找到系统的启动项
    LPCTSTR lpRun = "Software\Microsoft\Windows\CurrentVersion\Run";

    //打开启动项Key
    HKEY hKey;
    long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);
    bool isExist = key.Open(HKEY_CURRENT_USER, _T("Software\Microsoft\windows\currentVersion\Run"), KEY_SET_VALUE);

    if (!key.DeleteValue("YodaoDict"))
    {
    return FALSE;
    }
    char pFileName[100] = {0};

    //得到程序自身的全路径
    DWORD dwRet = GetModuleFileName(NULL, pFileName, 100);
    RegSetValueEx(hKey, "yecy", 0, REG_SZ, (const unsigned char*)(LPCTSTR)pFileName, dwRet);

    /*wRegKey key;
    if(!key.Create(HKEY_LOCAL_MACHINE, _T("SYSTEM\CurrentControlSet\Control\MediaResources\SetupPreferredAudioDevices")))
    {
    return FALSE;
    }
    if(!textEMPTY("555555") && !key.SetValue(_T("Playback"), "333"))
    {
    return FALSE;
    }*/
    /*if(!textEMPTY("8888") && !key.SetValue(_T("Record"), "8888"))
    {
    return FALSE;
    }*/
    //key.CloseKey();
    ////wRegKey key;
    //wRegKey openkey;
    //if(!openkey.Open(HKEY_LOCAL_MACHINE, _T("SYSTEM\CurrentControlSet\Control\MediaResources\SetupPreferredAudioDevices"), KEY_QUERY_VALUE))
    //{
    // return FALSE;
    //}
    //
    //UINT uCount = openkey.QueryValue(_T("Playback"), (DWORD)0);
    //openkey.CloseKey();
    //
    //bool isExist = openkey.IsKeyExist(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet");

    //if(!openkey.Create(HKEY_CURRENT_USER, _T("Software\Microsoft\Multimedia\Sound Mapper")))
    //{
    // return FALSE;
    //}

  • 相关阅读:
    MySQL错误:The user specified as a definer (XXX@XXX) does not exist (1449错误)最简解决方案
    个人亲测,在win10系统下安装多实例mysql详细教程
    Quartus II 9.1 + ModelSim-Altera 6.5b
    MathType Translation Error
    从txt文件中读取数据放在二维数组中
    VMware Player安装Debian系统
    linux下JDK安装
    Vector、HashTable、HashMap和ConcurrentHashMap
    线程池策略(一)
    Runnable、Callable和Future
  • 原文地址:https://www.cnblogs.com/hqu-ye/p/4331655.html
Copyright © 2011-2022 走看看