【C++】c++修改IE浏览器的Internet选项

windows开发经常会使用IE浏览器,例如Http编程。很多时候我们需要修改Internet选项中的cookies,高级设置,tls1.0 tls1.2之类的子项,这时可以使用修改注册表方法达到目的,微软内置软件多以注册表形式作为参数。问题又来了,注册表的选项纷繁复杂,里面的值代表什么意思?

下面教大家一个小技巧,在不知道修改项位置和数值含义的情况下,轻松找出目标并正确修改。

关于Internet选项注册表路径

Win+R呼出【运行】,输入 regedit 打开注册表工具,Internet选项在下面路径:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]

举一个栗子:

修改Internet选项 - 高级,启用tls1.0 & tls1.1 & tls1.2。

首先,我也不知道启用1.0,1.1,1.2需要怎么设置,原本是只开启1.0  1.1的,禁止了1.2。

第一步

在默认值的情况下,打开上文路径Internet Settings注册表,右击选择导出,命名为reg01。

 第二步

打开IE浏览器 - Internet选项 - 高级,手动把TLS1.2勾上,保存并关闭。再次导出Internet Settings注册表,命名为reg02。

第三步

打开文本对比工具,此处推荐一个在线对比网站 http://www.newjson.com/Static/Tools/Diff.html

导入reg01,reg02对比,发现 SecureProtocols数值改变了,由0x0280变成了0x0a80,其余数值没有变。便可以断定0x0a80就代表同时勾选TLS1.0  1.1  1.2。

 注册表中对应的内容如下

C++修改对应位置的注册表数值。

知道了修改项位置和数值内容,就可以coding了。c++代码如下

#include <windows.h>
#include <iostream>
using namespace std;

HKEY OpenKey(HKEY hRootKey, wchar_t* strKey)
{
    HKEY hKey;
    LONG nError = RegOpenKeyEx(hRootKey, strKey, NULL, KEY_ALL_ACCESS, &hKey);

    if (nError==ERROR_FILE_NOT_FOUND)
    {
        cout << "Creating registry key: " << strKey << endl;
        nError = RegCreateKeyEx(hRootKey, strKey, NULL, NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL, &hKey, NULL);
    }

    if (nError)
        cout << "Error: " << nError << " Could not find or create " << strKey << endl;

    return hKey;
}

void SetVal(HKEY hKey, LPCTSTR lpValue, DWORD data)
{
    LONG nError = RegSetValueEx(hKey, lpValue, NULL, REG_DWORD, (LPBYTE)&data, sizeof(DWORD));

    if (nError)
        cout << "Error: " << nError << " Could not set registry value: " << (char*)lpValue << endl;
}

DWORD GetVal(HKEY hKey, LPCTSTR lpValue)
{
    DWORD data;        DWORD size = sizeof(data);    DWORD type = REG_DWORD;
    LONG nError = RegQueryValueEx(hKey, lpValue, NULL, &type, (LPBYTE)&data, &size);

    if (nError==ERROR_FILE_NOT_FOUND)
        data = 0; // The value will be created and set to data next time SetVal() is called.
    else if (nError)
        cout << "Error: " << nError << " Could not get registry value " << (char*)lpValue << endl;

    return data;
}

int main()
{
    // 打开Internet选项位置
    HKEY hKey = OpenKey(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");
    DWORD vv = GetVal(hKey, L"SecureProtocols");  //0x0280
    vv = 2688; //0x0a80
    // 修改十进制数值
    SetVal(hKey, L"SecureProtocols", vv);
    RegCloseKey(hKey);
    
    return 0;
}

关于注册表编程,可以参考 https://www.cnblogs.com/john-h/p/5886870.html

举一反三

回看前面说的,如果想修改Internet选项的其他内容,只需要对比修改前后的regedit文本,找出对应项和对应数值。

这样,在不知道数值含义和参数位置情况下,也能轻松达到目的。

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值