I have a utility that reads data from the registry. Up to this point
it has been working well, all of the data that I have needed to read
has been in HKEY_LOCAL_MACHINE. The following is the routine that I
am using and that has been working for these entries:
Public Sub RegGetData(lSection As Long, sKeyName As String, sValueName
As String, sValue As String)
Dim lRetVal As Long
Dim hKey As Long
Dim lBuffSize As Long
sValue = Space(255)
lBuffSize = Len(sValue)
' Open the key
lRetVal = RegOpenKeyEx(lSection, sKeyName, 0, KEY_ALL_ACCESS,
hKey)
' Get the value
lRetVal = RegQueryValueEx(hKey, sValueName, 0, REG_SZ, sValue,
lBuffSize)
sValue = Left$(sValue, lBuffSize - 1)
' Close the key
RegCloseKey (hKey)
End Sub
(I know that I'm not passing back any return codes, I'm still
developing and I'll get to that later, right now I'm just checking
them through the debugger)
I now need to read something out of HKEY_CLASSES_ROOT. No matter what
key I try to access, I am getting a return code of 2 for the
RegOpenKeyEx. I have double checked, and the entries do exist. It
won't work for anything under HKEY_CLASSES_ROOT. I have tried
changing the permissions to KEY_READ. If I query a different section,
all is well. I just can't ready anything under HKEY_CLASSES_ROOT.
The user ID I am using has administrator privileges (I am on Windows
2000) It sounds like a permissions thing, but I can't figure out how
to get around it. Any ideas?
Thanks
Anna
--
--
Anna Rouse <Anna....@cci-triad.com> wrote in message
news:511e99f9.03090...@posting.google.com...
Really hard to tell for sure without seeing your declares and what
you're passing in the hKey and lpSubKey args, but a return of 2 is
ERROR_FILE_NOT_FOUND, which in this case would mean the key doesn't
exist. (Perhaps a typo in the keyname arg.) Also be sure it doesn't
have leading or trailing "\" delimiter chars.
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
The name of the key that I'm passing in is
TypeLib\{2F3042A1-65C6-4F01-A861-5781E4846791}\1.0\0\win32
But it doesn't matter what key I pass in, I always get a return code
of 2. That key does exist. I went into the registry, copied the key
value and manually copied that into the variable in the debugger, and
still got the same error. Plus, I tried other keys, such as "ADCS"
and "acwfile", and get the same result.
When I access something in HKEY_LOCAL_MACHINE it works fine. The key
I pass in then is
Software\CCI/Triad\TriadCatalog\Catalog
In this example, the subkey I pass in is null because I want the
default entry, but I haven't even gotten to that point yet, it's
failing in the open. hkey is zero because the open should fill it in
Very curious, never had a problem reading the registry like this
before ...
>My declares are
Yeah, that's odd allright. It really doesn't act like a security
issue, but what happens if you log in as admin?
>Just on a whim, I deleted the line that had the defines and retyped it
Yep, posting declares for Api questions can save a lot of wasted time.
<bg>
>My declares are
Anna, might just be a typo but this
Software\CCI/Triad\TriadCatalog\Catalog
(Software\CCI / Triad\TriadCatalog\Catalog)
should be this
Software\CCI\Triad\TriadCatalog\Catalog
Notice ^^^^ the key separator
Regards
steve
---------------------------
http://www.thesourcesoft.com
I'd bet big bucks the problem is because you're specifying KEY_ALL_ACCESS.
Don't do this! KEY_ALL_ACCESS is just what it says. The user MUST have
*all* Registry permissions in order for the RegOpenKeyEx function to succeed
when you specify KEY_ALL_ACCESS. Only admins have all Registry permissions.
So, for any user who is not part of the Admin group, the function will
always fail. Since you're querying a value, you should use KEY_READ. You'd
use KEY_WRITE if you need to write a value or create a new Registry key.
Very seldom do you ever need to specify any other access rights. You should
only use KEY_ALL_ACCESS in very specialized circumstances and only if you've
determined the logged on user is an admin.
Mike
Mike
Greg Wright
>.
>
HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsen...@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
On Thu, 2 Oct 2003 01:02:45 -0700, "Greg Wright" <gdwri...@cs.com>
wrote:
The reason the code submitted by "Anna" doesn't work on NT/2K/XP boxes is
that it's asking for full access to the registry keys (KEY_ALL_ACCESS). This
works fine on 95/98/ME because there's no registry security implementation
on those systems.
Best practice is never to ask for more permissions than you're going to
need. In this case KEY_QUERY_VALUE should be enough.
--
Björn Holmgren
Guide Konsult AB
"Greg Wright" <gdwri...@cs.com> wrote in message
news:195701c388bb$900f0070$a101...@phx.gbl...