VC:注册表:查询、删除项(CRegKey 的方法:Open、QueryValue、.DeleteValue、DeleteSubKey、RecurseDeleteKey)

//注册表查询
  //1
  CRegKey regkey;
  DWORD dValue;
  LPCTSTR lp="Console\\";
  if(regkey.Open(HKEY_CURRENT_USER,lp)==ERROR_SUCCESS)//打开
  {
   if(regkey.QueryValue(dValue,"WindowSize")==ERROR_SUCCESS)//进行查询
   {
    cout<<dValue<<endl;//输出查询到得值
   }
   else
   {
    cout<<"Query Error"<<endl;
   }
   regkey.Close();
  }
  else
  {
   cout<<"Open error!"<<endl;
  }

 

              CRegKey regkey;

              DWORD dwCount=1024;

              char sValue[1024];

              //LPCTSTR sValue;//LPCTSTR是const类型不能用

              LPCTSTR valueName="";

              LPCTSTR lpstr="*\\shell\\";//只能删除其下的健值

              if(regkey.Open(HKEY_CLASSES_ROOT,lpstr)==ERROR_SUCCESS)//打开

              {

                     HKEY hKey;

              //     LPCTSTR hSubKey;

                     hKey=HKEY_CLASSES_ROOT;

              //     hSubKey="*\\shell\\QQ\\";

                     ::RegDeleteKey(hKey,lpstr);

                     ::RegDeleteValue(hKey,"");

 

             

                     regkey.DeleteValue("");//删除默认值

                     //注意:regkey.DeleteValue(valuename);

              //     regkey.DeleteSubKey("command");//不能删除含子键的项

                     regkey.RecurseDeleteKey("QQ");//删除含子键的项(QQ是键名)

                     if(regkey.QueryValue(sValue,valueName,&dwCount)==ERROR_SUCCESS)//进行查询

                     {

                            cout<<sValue<<endl;//输出查询到得值

                           

                     }

                     else

                     {

                            cout<<"Query Error"<<endl;

                     }

              }

              else

              {

                     cout<<"Open error!"<<endl;

              }

      

      

              regkey.Close();

                    

你可能感兴趣的:(delete)