Windows注册表操作基础代码
生活随笔
收集整理的這篇文章主要介紹了
Windows注册表操作基础代码
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Windows注冊表操作基礎代碼
?
??? Windows下對注冊表進行操作使用的一段基礎代碼Reg.h:
#pragma?once#include<assert.h>
#include<windows.h>
class?Reg
{
????HKEY?hkey;
public:
????void?open(HKEY?root,char*subKey);//打開注冊表鍵,不存在則創(chuàng)建
????void?del(HKEY?root,char*subKey);//刪除注冊表鍵
????void?close();//關閉注冊表鍵
????void?setValue(char*name,char*data);//設置注冊表值,不存在則創(chuàng)建
????void?getValue(char*name,char*value);//獲取注冊表值
????void?delValue(char*name);//刪除注冊表值
};
void?Reg::open(HKEY?root,char*subKey)
{
????long?lret=RegCreateKeyEx(root,(LPCTSTR)subKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hkey,NULL);
????assert(lret==ERROR_SUCCESS);
}
void?Reg::del(HKEY?root,char*subKey)
{
????long?lret=RegDeleteKey(root,(LPCTSTR)subKey);
????assert(lret==ERROR_SUCCESS);
}
void?Reg::close()
{
????long?lret=RegCloseKey(hkey);
????assert(lret==ERROR_SUCCESS);
}
void?Reg::setValue(char*name,char*data)
{
????long?lret=RegSetValueEx(hkey,(LPCTSTR)name,0,REG_SZ,(BYTE*)data,(DWORD)strlen(data));
????assert(lret==ERROR_SUCCESS);
}
void?Reg::getValue(char*name,char*value)
{
????long?lret=RegQueryValueEx(hkey,(LPCTSTR)name,0,(LPDWORD)REG_SZ,(BYTE*)value,(LPDWORD)strlen(value));
????assert(lret==ERROR_SUCCESS);
}
void?Reg::delValue(char*name)
{
????long?lret=RegDeleteValue(hkey,(LPCTSTR)name);
????assert(lret==ERROR_SUCCESS);
}
?? 對注冊表操作需要保證編譯器處于管理員權(quán)限,否則無法正常執(zhí)行注冊表操作。
?
轉(zhuǎn)載于:https://www.cnblogs.com/fanzhidongyzby/archive/2012/07/31/2617015.html
總結(jié)
以上是生活随笔為你收集整理的Windows注册表操作基础代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10网络共享计算机名,手把手教你w
- 下一篇: java信息管理系统总结_java实现科