views:

265

answers:

4

I cannot read from the registry unless I run my application in administrator mode. I am building a preview handler, using the IPreviewHandler interface, and I require GUIDs for file types located in HKEY_CLASSES_ROOT.

How can I access this information without elevating my application to adminstrator. I am using Delphi but happy for any sample code.

Thanks, Phillip

+8  A: 

When you create a TRegistry object, by default ALL_ACCESS is requested.

If you only need to read values, use

reg := TRegistry.Create(KEY_QUERY_VALUE);
glob
+6  A: 

To add to globs answer, you could also use the TRegistry.OpenKeyReadOnly(); method.

Nat
A: 

I would recommend to use KEY_READ constant instead of KEY_QUERY_VALUE:

reg:=TRegistry.Create(KEY_READ);

or:

reg:=TRegistry.Create;
reg.Access:=KEY_READ;

Why? KEY_QUERY_VALUE seems to be exactly what's needed here. The OP is wanting to ask for the value of a registry key and no more.
Ken White
Because KEY_READ is more common and generic. And OP's message is not clear about what he is doing
A: 

Microsoft has decided that they don't want programmers messing around with HKEY_CLASSES_ROOT anymore so have required administrator mode access to get to it in Windows 7 (and I believe Vista also).

Instead, they want you to look in HKEY_CURRENT_USER, which should contain the same GUIDs you need, but specific for the user currently logged in.

See if the GUIDs you need are in HKEY_CURRENT_USER. If so, access those and you won't need administrator mode for reading or writing.

lkessler