bool RegisterQAppAssociation::showNativeDefaultAppSettingsUi() { if (!isVistaOrNewer()) { return false; } #ifdef _WIN32_WINNT_WIN8 IApplicationActivationManager* pActivator; HRESULT hr = CoCreateInstance(CLSID_ApplicationActivationManager, nullptr, CLSCTX_INPROC, IID_IApplicationActivationManager, (void**)&pActivator); if (!SUCCEEDED(hr)) { return false; } DWORD pid; hr = pActivator->ActivateApplication( L"windows.immersivecontrolpanel_cw5n1h2txyewy" // appUserModelId of "Settings" L"!microsoft.windows.immersivecontrolpanel", // in Windows Store L"page=SettingsPageAppsDefaults", AO_NONE, &pid); if (!SUCCEEDED(hr)) { return false; } // Do not check error because we could at least open // the "Default apps" setting. pActivator->ActivateApplication( L"windows.immersivecontrolpanel_cw5n1h2txyewy" L"!microsoft.windows.immersivecontrolpanel", L"page=SettingsPageAppsDefaults" L"&target=SystemSettings_DefaultApps_Browser", AO_NONE, &pid); pActivator->Release(); #else // Vista or Win7 IApplicationAssociationRegistrationUI* pAARUI = NULL; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistrationUI), reinterpret_cast< void** > (&pAARUI)); if (!SUCCEEDED(hr)) { return false; } hr = pAARUI->LaunchAdvancedAssociationUI(reinterpret_cast<LPCWSTR>(_appRegisteredName.utf16())); pAARUI->Release(); #endif // _WIN32_WINNT_WIN8 return true; }
bool WindowsPlatformIntegration::setAsDefaultBrowser() { if (!isBrowserRegistered() && !registerToSystem()) { return false; } QSettings registry(QLatin1String("HKEY_CURRENT_USER\\Software"), QSettings::NativeFormat); for (int i = 0; i < m_registrationPairs.count(); ++i) { if (m_registrationPairs.at(i).second == ProtocolType) { registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/DefaultIcon/."), m_applicationFilePath + QLatin1String(",1")); registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/shell/open/command/."), QLatin1String("\"") + m_applicationFilePath + QLatin1String("\" \"%1\"")); } else { registry.setValue(QLatin1String("Classes/") + m_registrationPairs.at(i).first + QLatin1String("/."), m_registrationIdentifier); } } registry.setValue(QLatin1String("Clients/StartmenuInternet/."), m_registrationIdentifier); registry.sync(); if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) { IApplicationAssociationRegistrationUI *applicationAssociationRegistrationUI = NULL; HRESULT result = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, NULL, CLSCTX_INPROC_SERVER, IID_IApplicationAssociationRegistrationUI, (LPVOID*)&applicationAssociationRegistrationUI); if (result == S_OK && applicationAssociationRegistrationUI) { result = applicationAssociationRegistrationUI->LaunchAdvancedAssociationUI(m_registrationIdentifier.toStdWString().c_str()); applicationAssociationRegistrationUI->Release(); if (result == S_OK) { return true; } } Console::addMessage(QCoreApplication::translate("main", "Failed to run File Associations Manager, error code: %1").arg(result), Otter::OtherMessageCategory, ErrorMessageLevel); } else { SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_DWORD | SHCNF_FLUSH, NULL, NULL); Sleep(1000); } return true; }
bool CFileAssoc::ShowWindowsAssocDialog() const { IApplicationAssociationRegistrationUI* pAARUI; HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&pAARUI)); bool success = (SUCCEEDED(hr) && pAARUI != nullptr); if (success) { pAARUI->LaunchAdvancedAssociationUI(m_strRegisteredAppName); pAARUI->Release(); } return success; }