PDA

View Full Version : QSettings HKEY_CLASSES_ROOT access



Arsenic
5th July 2007, 03:07
I was wondering if it was possible with Qt to access HKEY_CLASSES_ROOT

like so:


QSettings settings;
if(settings.value("HKEY_CLASSES_ROOT\\Cool\\Shell\\open\\ddeexec\\Top ic", QString("")) == QString("")){
settings.setValue("HKEY_CLASSES_ROOT\\Cool", "AValue");
// more registry values.
}


I wasn't able to get it to work, and if someone can show me a way it would be great, because I tried to read through the Settings docs for hours...

Thanks,.

jpn
5th July 2007, 10:32
From QSettings docs: Platform Specific Notes (http://doc.trolltech.com/4.3/qsettings#platform-specific-notes) - Accessing the Windows Registry Directly:


On Windows, QSettings also lets you access arbitrary entries in the system registry. This is done by constructing a QSettings object with a path in the registry and QSettings::NativeFormat. For example:


QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office",
QSettings::NativeFormat);

All the registry entries that appear under the specified path can be read or written through the QSettings object as usual (using forward slashes instead of backslashes). For example:


settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);

Note that the backslash character is, as mentioned, used by QSettings to separate subkeys. As a result, you cannot read or write windows registry entries that contain slashes or backslashes; you should use a native windows API if you need to do so.


Hard to say about an exact solution without knowing more about your problem (content of the registry, which key/value are you interested in...). Anyway, here's another example:


QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
settings.beginGroup(".png");
qDebug() << settings.value("Content Type").toString(); // outputs "image/png"
settings.endGroup();
settings.beginGroup(".jpg");
qDebug() << settings.value("Content Type").toString(); // outputs "image/jpeg"
settings.endGroup();

pdolbey
5th July 2007, 20:39
Back in the old days of Windows NT, HKEY_CLASSES_ROOT was a simple alias for HKEY_LOCAL_MACHINE\SOFTWARE\Classes. This was a useful thing to know as when trying to read a remote registry with regedt32 (not regedit which never ran remotely), you could exploit this alias.

However in the days of Windows 2000/3 and XP, HKEY_CLASSES_ROOT is actually created from a merger of HKEY_LOCAL_MACHINE\SOFTWARE\Classes and HKEY_CURRENT_USER\SOFTWARE\Classes with values in the latter overriding values in the former. It is this feature that enables features like per-user COM object registration. You need administation right to register objects globally on the machine. You can prove this with regedit by creating the same key in both hives, then seeing which one takes precedence.

Hope this helps

Pete

Arsenic
7th July 2007, 08:35
Thanks guys, especially pdolbey, I didn't know HKEY_ROOT_CLASSeS was only a repitition of HKCU/soft/class and HKLM.

pdolbey
7th July 2007, 12:10
I guess it depends on your application as to whether you're trying to affect all users or just the logged-on user. I am involved in an ever increasing locked-down environment for UK government, where the user priviledges to change HKLM are virtually non-existent. This was a "sneaky"" hack I uncovered that allowed me to change DCOM server settings on a HKCU per-user basis for HKLM registered COM objects.

Pete