对Windows注册表进行注册操作

1。读取xml文件,将AllowPopupWindow.xml文件中url存入到vector中  


<?xml version="1.0" encoding="utf-16"?>
<TrustDomain attribute="site">
  <!--id 唯一标识, rid 语言资源标识, action 处理方法(1-add, 2-del)-->
  <Item id="3601" action="1" url=" http://*.bjrcb.com/" />
  <Item id="3602" action="1" url=" https://*.bjrcb.com/" />
  <Item id="3603" action="1" url=" http://www.bjrcb.com/" />
  <Item id="3604" action="1" url=" https://corporatebank.bjrcb.com/" />
  <Item id="3605" action="1" url=" https://ibs.bjrcb.com/" />
  <Item id="3606" action="1" url=" http://*.cfca.com.cn/" />
  <Item id="3607" action="1" url=" http://www.cfca.com.cn/" />
</TrustDomain>


vector<_bstr_t> m_popupWindowItems;

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();
//m_SiteAction.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);
//long action;
//pXmlHelper->GetNodeAttribute(pNode, "action", action);
//m_SiteAction.push_back(action);
}
}
}

return TRUE;
}

2.将存储的vector中url进行添加到注册表中
BOOL CIEOpt::AddPopupWindow()
{
LoadPopupWindowUrlList();
unsigned int i = 0;

DWORD dwReg_type = REG_BINARY;
LONG lRet = ERROR_SUCCESS;
HKEY hkey = NULL;
_bstr_t strUrl = _T("");
char chexValue[2] = {(char)0x00,(char)0x00};
_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)
{
return FALSE;
}

strUrl = m_ popupWindowItems.at(i);
if (strUrl.length() == 0)
{
return FALSE;
}

lRet = RegSetValueEx(hkey, strUrl, 0, dwReg_type, (const BYTE*)strValue.GetBSTR(), strValue.length() * 2);

if (lRet != ERROR_SUCCESS)
{
RegCloseKey(hkey);
return FALSE;
}
RegCloseKey(hkey);
i++;
}


return TRUE;
}

3.注意点:

若lRet = RegOpenKeyEx的返回值为2的时候,有三点需要注意检查 一是路径真的不存在,二是参数错误,三可能是权限问题


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值