c++读取的注册表详解_C/C++语言_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

c++读取的注册表详解

作者:黑客防线网安C/C++教程基地 来源:黑客防线网安C/C++教程基地 浏览次数:0

黑客防线网安网讯:  1.读注册表// 读取注册表CString ReadRegisteTable(CString root,CString path, CString key){HKEY hAppKey;LPCTSTR WINDS_SERVICE_REGISTRY_KEY=path;LPCTSTR DATA_FILE_SUB_KEY=key;c...
  1.读注册表
// 读取注册表
CString ReadRegisteTable(CString root,CString path, CString key)
{
HKEY hAppKey;
LPCTSTR WINDS_SERVICE_REGISTRY_KEY=path;
LPCTSTR DATA_FILE_SUB_KEY=key;
char szDataFile[80];
if(root=="HKEY_LOCAL_MACHINE")
{
if (ERROR_SUCCESS == RegOpenKeyEx (
HKEY_LOCAL_MACHINE,
WINDS_SERVICE_REGISTRY_KEY,
0,
KEY_READ,
&hAppKey))
{
ULONG cbSize = MAX_PATH*sizeof(TCHAR);
DWORD dwFlag = RegQueryValueEx (
hAppKey,
DATA_FILE_SUB_KEY,
NULL,
NULL,
(LPBYTE)szDataFile,&cbSize);
RegCloseKey (hAppKey);
if (ERROR_SUCCESS == dwFlag)
{
CString strDate=szDataFile; //MessageBox(strDate);
if(strDate.GetLength()>0) return strDate;
else return "";
}
return "";
}
}
if(root=="HKEY_CURRENT_USER")
{
if (ERROR_SUCCESS == RegOpenKeyEx (
HKEY_CURRENT_USER,
WINDS_SERVICE_REGISTRY_KEY,
0,
KEY_READ,
&hAppKey))
{
ULONG cbSize = MAX_PATH*sizeof(TCHAR);
DWORD dwFlag = RegQueryValueEx (
hAppKey,
DATA_FILE_SUB_KEY,
NULL,
NULL,
(LPBYTE)szDataFile,&cbSize);
RegCloseKey (hAppKey);
if (ERROR_SUCCESS == dwFlag)
{
CString strDate=szDataFile; //MessageBox(strDate);
if(strDate.GetLength()>0) return strDate;
else return "";
}
return "";
}
}
return "";
}[nextqage]
2.写注册表
// 修改注册表
BOOL ModifyRegisteTable(CString root,CString path, CString key, CString value)
{
HKEY hAppKey;
DWORD dwDisposition = MAX_PATH*sizeof(TCHAR);
LPCTSTR WINDS_SERVICE_REGISTRY_KEY=path;
LPCTSTR DATA_FILE_SUB_KEY=key;
char szDataFile[80]; strcpy(szDataFile,value);
if(root=="HKEY_LOCAL_MACHINE")
{
if (ERROR_SUCCESS != RegCreateKeyEx (
HKEY_LOCAL_MACHINE,
WINDS_SERVICE_REGISTRY_KEY,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hAppKey,
&dwDisposition))
{
return false;
}
else
{
if (ERROR_SUCCESS != RegSetValueEx (hAppKey,
DATA_FILE_SUB_KEY,
0,
REG_SZ,
(LPBYTE)szDataFile,
(lstrlen (szDataFile)+1)*sizeof(TCHAR)))
{
return false;
}
RegCloseKey (hAppKey);
}
}
if(root=="HKEY_CURRENT_USER")
{
if (ERROR_SUCCESS != RegCreateKeyEx (
HKEY_CURRENT_USER,
WINDS_SERVICE_REGISTRY_KEY,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hAppKey,
&dwDisposition))
{
return false;
}
else
{
if (ERROR_SUCCESS != RegSetValueEx (hAppKey,
DATA_FILE_SUB_KEY,
0,
REG_SZ,
(LPBYTE)szDataFile,
(lstrlen (szDataFile)+1)*sizeof(TCHAR)))
{
return false;
}
RegCloseKey (hAppKey);
}
}
return true;
}
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-15413-1.html
网站维护教程更新时间:2012-04-04 22:54:29  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer