Results 1 to 5 of 5

Thread: QSettings HKEY_CLASSES_ROOT access

  1. #1
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default QSettings HKEY_CLASSES_ROOT access

    I was wondering if it was possible with Qt to access HKEY_CLASSES_ROOT

    like so:
    Qt Code:
    1. QSettings settings;
    2. if(settings.value("HKEY_CLASSES_ROOT\\Cool\\Shell\\open\\ddeexec\\Topic", QString("")) == QString("")){
    3. settings.setValue("HKEY_CLASSES_ROOT\\Cool", "AValue");
    4. // more registry values.
    5. }
    To copy to clipboard, switch view to plain text mode 

    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,.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSettings HKEY_CLASSES_ROOT access

    From QSettings docs: 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:

    Qt Code:
    1. QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Office",
    2. QSettings::NativeFormat);
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. QSettings settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);
    2. settings.beginGroup(".png");
    3. qDebug() << settings.value("Content Type").toString(); // outputs "image/png"
    4. settings.endGroup();
    5. settings.beginGroup(".jpg");
    6. qDebug() << settings.value("Content Type").toString(); // outputs "image/jpeg"
    7. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    Arsenic (7th July 2007), WinchellChung (19th September 2007)

  4. #3
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSettings HKEY_CLASSES_ROOT access

    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

  5. The following user says thank you to pdolbey for this useful post:

    Arsenic (7th July 2007)

  6. #4
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSettings HKEY_CLASSES_ROOT access

    Thanks guys, especially pdolbey, I didn't know HKEY_ROOT_CLASSeS was only a repitition of HKCU/soft/class and HKLM.

  7. #5
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSettings HKEY_CLASSES_ROOT access

    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
    Last edited by pdolbey; 7th July 2007 at 11:10. Reason: typo

Similar Threads

  1. ODBC and MS Access
    By allensr in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2007, 23:41
  2. Replies: 1
    Last Post: 4th October 2006, 16:05
  3. Replies: 5
    Last Post: 14th July 2006, 22:42
  4. inserting string > 127 characters to MS Access
    By jh in forum Qt Programming
    Replies: 0
    Last Post: 12th May 2006, 17:11
  5. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.