c++ - 如何通过 C++ 程序通过注册表编辑更改 IE 9 的默认搜索提供程序?

标签 c++ windows windows-7 registry internet-explorer-9

我想通过编辑注册表文件来更改 IE (9) 的默认搜索提供程序。我已按照链接中给出的步骤进行操作:http://www.online-tech-tips.com/internet-explorer-tips/change-default-search-engine-ie/ .

但是当我将 DefaultScope 值更改为 SearchScopes 中的范围时,然后重新启动计算机,或打开 IE,在地址栏中进行搜索,或关闭 IE。 DefaultScope 的值恢复到之前的值。

为什么?或者我的错误是什么?

如何以编程方式更改 IE 的搜索提供程序引擎(不在 IE 中,可能通过注册表或在我的 C++ 代码中)? (我写了一个C++程序,需要改变IE的搜索引擎)

I have written this function for Firefox or Chrome. It works well. With Firefox, those information is stored in the prefs.js file. I can read or write information requisite to this file easily. With Chrome, those information is stored in two files in user profile folder: Preferences and Web Data files. The Preferences file is a JSON file. I get those information easily by parsing this JSON file. But to set search engine provider information for Chrome. We need to change those information in Web Data file. Web Data file is a SQLite file. I use SQLite library to access this.

With Internet Explorer, I can get those information in that registry path. But I can't set those information with that registry path. So, I think, like Chrome, IE (or registry) needs to change those information somewhere. But I don't know where.

最佳答案

Here是对您问题的详细回答。

使用 IOpenServiceManager 有两个选项可供选择:

CComQIPtr<IOpenServiceManager> spManager;
check(spManager.CoCreateInstance(__uuidof(OpenServiceManager), CLSCTX_ALL));

CComQIPtr<IOpenService> spService;
check(spManager->InstallService(PU_POSTINSTALL_ANT_SEARCH_PROVIDER_XML, &spService));

if(makeItDefault)
{
    // Request that the user change their search default
    check(spService->SetDefault( TRUE, hPromptParent ));
}

或者修改注册表:

LPCWSTR searchScopesKeyName = L"Software\\Microsoft\\Internet Explorer\\SearchScopes";

createKey(rootKey, HKEY_CURRENT_USER, searchScopesKeyName);

std::wstring clsidString = findProviderClsid(false);
if( clsidString.empty() )
    clsidString = mc_providerClsidString;

if( makeItDefault )
    setStringValue( rootKey, mc_defaultScopeValueName, clsidString.c_str() );

ATL::CRegKey subKey;
createKey(subKey, rootKey.m_hKey, clsidString.c_str() );

setStringValue( subKey, mc_displayNameValueName, mc_providerName );
setStringValue( subKey, mc_faviconUrlValueName, mc_providerFaviconURL );
setStringValue( subKey, mc_urlValueName, mc_providerURL );

关于c++ - 如何通过 C++ 程序通过注册表编辑更改 IE 9 的默认搜索提供程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9493480/

相关文章:

c++ - C++ 中的 DBL_MAX 是什么?

c++ - 有哪些用于非 MFC、Win32 C++ 应用程序的 *slick* UI 库/框架/工具?

windows - 如何从命令行打开 WinSCP GUI 并登录服务器

iis-7 - Powershell Get-WebSite名称参数被忽略

php - WAMP Server V 2.5 图标为橙色,无响应且无菜单

c++ - 截取不可见窗口的屏幕截图

c++ - 使用模板进行隐式类型转换

windows - cmd 启动命令 ignores/min 开关

mysql - 未知选项简写形式 m

debugging - 是否存在与 Windows 7 内核符号相关的已知问题?