Cannot read from registry - HKEY_CLASSES_ROOT if not running in Administrator Mode
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.
T开发者_JAVA百科hanks, Phillip
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);
To add to globs answer, you could also use the TRegistry.OpenKeyReadOnly();
method.
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;
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.
精彩评论