写注册表操作
来源:互联网 发布:nba2016年胜负数据 编辑:程序博客网 时间:2024/06/01 20:27
1.使用RegOpenKeyEx进行打开注册表
2.使用RegCreateKeyEx进行创建注册表
3.使用RegSetValueEx进行设置值
4。RegCloseKey关闭注册表
BOOL CIEOpt::AddPopupWindow()
{
LoadPopupWindowUrlList();
unsigned int i = 0;
DWORD dwReg_type = REG_BINARY;
LONG lRet = ERROR_SUCCESS;
HKEY hkey = NULL;
_bstr_t strUrl = _T("");
BYTE chexValue[4] = { 0,0,0,0 };
_bstr_t strValue = _bstr_t(chexValue)/*_T("")*/;
while (i < m_popupWindowItems.size())
{
lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\New Windows\\Allow"), 0, KEY_ALL_ACCESS | KEY_WOW64_32KEY, &hkey);
if (lRet != ERROR_SUCCESS)
{
lRet = RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\New Windows\\Allow"), 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL);
if (lRet != ERROR_SUCCESS)
{
return FALSE;
}
}
strUrl = m_popupWindowItems.at(i);
if (strUrl.length() == 0)
{
}
else
{
lRet = RegSetValueEx(hkey, strUrl, 0, dwReg_type, (const BYTE*)strValue.GetBSTR(), strValue.length());
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hkey);
return FALSE;
}
}
RegCloseKey(hkey);
i++;
}
return TRUE;
}
BOOL CIEOpt::LoadPopupWindowUrlList()
{
//装载弹出窗口允许的网站地址
_bstr_t bstrConfigPath;
_bstr_t bstrFileName;
if (!GetConfigDir(bstrConfigPath))
{
return FALSE;
}
bstrConfigPath += _T("AllowPopupWindow.xml");
bstrFileName = bstrConfigPath;
_bstr_t m_bstrXPath = _T("TrustDomain/Item");
m_popupWindowItems.clear();
util_xml::CXmlHelper* pXmlHelper = new util_xml::CXmlHelper;
pXmlHelper->m_bstrXmlFileName = bstrFileName;
BOOL bRet = pXmlHelper->Load();
if (!bRet)
{
WRITE_WARNING_LOG(_T("info: allowPopupwindow.xml load fail!\n"));
return FALSE;
}
else
{
CComQIPtr<IXMLDOMNodeList> nodeList;
pXmlHelper->SelectXmlNodes(m_bstrXPath, nodeList);
long lCount;
nodeList->get_length(&lCount);
for (int i = 0; i < lCount; i++)
{
CComQIPtr<IXMLDOMNode> pNode;
nodeList->get_item(i, &pNode);
if (pNode != NULL)
{
_bstr_t pNewItem;
pXmlHelper->GetNodeAttribute(pNode, "url", pNewItem);
m_popupWindowItems.push_back(pNewItem);
}
}
}
return TRUE;
}
{
LoadPopupWindowUrlList();
unsigned int i = 0;
DWORD dwReg_type = REG_BINARY;
LONG lRet = ERROR_SUCCESS;
HKEY hkey = NULL;
_bstr_t strUrl = _T("");
BYTE chexValue[4] = { 0,0,0,0 };
_bstr_t strValue = _bstr_t(chexValue)/*_T("")*/;
while (i < m_popupWindowItems.size())
{
lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\New Windows\\Allow"), 0, KEY_ALL_ACCESS | KEY_WOW64_32KEY, &hkey);
if (lRet != ERROR_SUCCESS)
{
lRet = RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Internet Explorer\\New Windows\\Allow"), 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL);
if (lRet != ERROR_SUCCESS)
{
return FALSE;
}
}
strUrl = m_popupWindowItems.at(i);
if (strUrl.length() == 0)
{
}
else
{
lRet = RegSetValueEx(hkey, strUrl, 0, dwReg_type, (const BYTE*)strValue.GetBSTR(), strValue.length());
if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hkey);
return FALSE;
}
}
RegCloseKey(hkey);
i++;
}
return TRUE;
}
BOOL CIEOpt::LoadPopupWindowUrlList()
{
//装载弹出窗口允许的网站地址
_bstr_t bstrConfigPath;
_bstr_t bstrFileName;
if (!GetConfigDir(bstrConfigPath))
{
return FALSE;
}
bstrConfigPath += _T("AllowPopupWindow.xml");
bstrFileName = bstrConfigPath;
_bstr_t m_bstrXPath = _T("TrustDomain/Item");
m_popupWindowItems.clear();
util_xml::CXmlHelper* pXmlHelper = new util_xml::CXmlHelper;
pXmlHelper->m_bstrXmlFileName = bstrFileName;
BOOL bRet = pXmlHelper->Load();
if (!bRet)
{
WRITE_WARNING_LOG(_T("info: allowPopupwindow.xml load fail!\n"));
return FALSE;
}
else
{
CComQIPtr<IXMLDOMNodeList> nodeList;
pXmlHelper->SelectXmlNodes(m_bstrXPath, nodeList);
long lCount;
nodeList->get_length(&lCount);
for (int i = 0; i < lCount; i++)
{
CComQIPtr<IXMLDOMNode> pNode;
nodeList->get_item(i, &pNode);
if (pNode != NULL)
{
_bstr_t pNewItem;
pXmlHelper->GetNodeAttribute(pNode, "url", pNewItem);
m_popupWindowItems.push_back(pNewItem);
}
}
}
return TRUE;
}
阅读全文
0 0
- 写注册表操作
- 自写的注册表操作函数
- 写注册表
- 写注册表
- 写注册表
- 刚写的注册表操作C#类,请指教
- 自己写的一个注册表操作类----相当实用
- Python写自动化之注册表的读写操作
- C#操作开机自启动(写进注册表)
- 操作注册表
- 注册表操作
- 注册表操作
- 操作注册表
- 注册表操作
- 注册表操作
- 注册表操作
- 注册表操作
- 注册表操作
- 推荐学习Vue的博客,质量很高,入门到精通
- os.Open()和os.OpenFile()
- CCF——图像旋转
- 数据挖掘之聚类分析
- 欧拉角以及方向余弦
- 写注册表操作
- 几道js面试题
- linux mysql 更改MySQL数据库目录位置
- (五)jQuery 遍历
- 工作笔记
- ofo_数字变化
- 正能量句子
- hadoop、hbase、hive、zookeeper版本对应关系
- 01-HTML5的设计原理