PDA

View Full Version : QSettings putting Windows registry keys in the wrong location



ComServant
26th October 2011, 22:00
QSettings putting Windows registry keys in the wrong location. Here's how I'm using it:


QSettings *registry = new QSettings("HKEY_CLASSES_ROOT\\SystemFileAssociations", QSettings::NativeFormat);
registry->setValue("TEST", "Test");

It's putting a subkey "TEST" with a value "Test" properly, but it's saving it here instead:
HKEY_CURRENT_USER\Software\Classes\SystemFileAssoc iations (Ignore the space... the forum is messing it up)

How do I make it place the key where I tell it to place it, instead of where it thinks I should place it?


[edit:] Qt 4.7 on Windows 7 32bit Home and Premium

ChrisW67
26th October 2011, 22:43
Are you running the program with administrative rights?

ComServant
26th October 2011, 22:59
Just tried running as admin. No go.
Plus, I don't want my users to have to run as admin to use the tool.

I found this post: http://www.qtcentre.org/threads/18168-reading-windows-registry?p=90772#post90772
Seems to imply QSettings does not give full access to the registry, which is a shame.

Qt ought to have a QWindowsRegistry class for wrapped native access, on the Windows version of Qt. Looking at the ugly convoluted legacy-filled crummy native Windows functions, and seeing if I can use them properly.

ChrisW67
27th October 2011, 00:34
You are trying to modify a global file association by writing into that area. You will not be able to do that as an unprivileged user.

I cannot reproduce your symptoms with a test program on XP and Win 7 (32).

On XP, where there are no restrictions, the TEST value was written where expected.
On Windows 7.

When "Run as Adminstrator..." is used the application writes where you are expecting (and the value is mirrored in HKLM/Software/Classes/SystemFileAssociation)
As an unprivileged user the TEST value was not written anywhere in my registry regardless of whether the application was being UAC virtualised (manifest or not). I was expecting registry virtualisation to have moved the errant attempt into the virtual store, but this does not seem to have happened.

The HKCU registry key you mention does not appear on my machine at all.

ComServant
27th October 2011, 15:57
this->registry = new QSettings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
this->registry->setValue("\\SystemFileAssociations\\.png\\shell\\View image tiled\\command", "T12345");

Results in "HKEY_CLASSES_ROOT" having an entry *named* "HKEY_CLASSES_ROOT/SystemFileAssociations/.png/shell/View image tiled/command" with a value of "T12345"



this->registry = new QSettings("HKEY_CLASSES_ROOT\\SystemFileAssociations\\.png\\s hell\\View image tiled\\command", QSettings::NativeFormat);
this->registry->setValue(".", "T12345");

Results in nothing being created if in non-admin, but created in the right spot if running as admin.
So setValue() assumes the first parameter is a complete name, and not a path to a name, even if broken with slashes.

Alright, so I need elevated permissions, and I need to use a different QSettings for each key I want to edit.
I'll try and have my current program execute the settings window as a sub-program or something.