diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-06-21 09:15:52 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2017-07-14 12:19:51 +0000 |
commit | 9a6d57385c49fa702319139ae1f2e471520963ee (patch) | |
tree | 43925cf493483f5a2c57187777a0e32189846e9d | |
parent | d36199ce84191e029bb5c81382367976bd0ade85 (diff) | |
download | qtactiveqt-9a6d57385c49fa702319139ae1f2e471520963ee.tar.gz |
Fallback to [Un]RegisterTypeLibForUser if the admin access fails
If the user cannot register the control due to lacking admin rights then
it should fall back to the user registration so that it can still
successfully be registered.
Change-Id: Idb514c2e02d8e7fb084a23182dcc2a793eb12d08
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | src/activeqt/control/qaxserver.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/activeqt/control/qaxserver.cpp b/src/activeqt/control/qaxserver.cpp index 6985cdd..45f6940 100644 --- a/src/activeqt/control/qaxserver.cpp +++ b/src/activeqt/control/qaxserver.cpp @@ -231,19 +231,35 @@ HRESULT UpdateRegistry(BOOL bRegister) qAxTypeLibrary->GetLibAttr(&libAttr); if (!libAttr) return SELFREG_E_TYPELIB; - - if (bRegister) - RegisterTypeLib(qAxTypeLibrary, reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), 0); - else - UnRegisterTypeLib(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, libAttr->syskind); - + bool userFallback = false; + if (bRegister) { + if (RegisterTypeLib(qAxTypeLibrary, + reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), 0) == TYPE_E_REGISTRYACCESS) { +#ifndef Q_CC_MINGW + // MinGW does not have RegisterTypeLibForUser() implemented so we cannot fallback in this case + RegisterTypeLibForUser(qAxTypeLibrary, reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), 0); + userFallback = true; +#endif + } + } else { + if (UnRegisterTypeLib(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, + libAttr->syskind) == TYPE_E_REGISTRYACCESS) { +#ifndef Q_CC_MINGW + // MinGW does not have RegisterTypeLibForUser() implemented so we cannot fallback in this case + UnRegisterTypeLibForUser(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, libAttr->syskind); + userFallback = true; +#endif + } + } + if (userFallback) + qWarning("QAxServer: Falling back to registering as user for %s due to insufficient permission.", qPrintable(module)); qAxTypeLibrary->ReleaseTLibAttr(libAttr); // check whether the user has permission to write to HKLM\Software\Classes // if not, use HKCU\Software\Classes QString keyPath(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes")); QScopedPointer<QSettings> settings(new QSettings(keyPath, QSettings::NativeFormat)); - if (!settings->isWritable()) { + if (userFallback || !settings->isWritable()) { keyPath = QLatin1String("HKEY_CURRENT_USER\\Software\\Classes"); settings.reset(new QSettings(keyPath, QSettings::NativeFormat)); } |