Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with registry API 2

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
0
0
NZ
Hi all

I am using someone else's code. When I encountered the line

lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "RegistryLoc",0,_ KEY_ALL_ACCESS, hKey)

it came up with an error saying method or data member not defined. I did a search and found that this RegOpenKeyEx is an API for accessing the Registry. I copied and pasted the following code from MSDN into my project:

Declare Function RegOpenKeyEx Lib "advapi32" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long

Now when I run it, it comes up with an error where I pass the API HKEY_LOCAL_MACHINE saying variable not defined.
If I put HKEY_LOCAL_MACHINE in quotes, the program generates an error.

What am I doing wrong?? Any advice, please! :cool:
 
You haven't defined HKEY_LOCAL_MACHINE. You might need these values for your app.
[tt]
Const REG_SZ As Long = 1
Const REG_DWORD As Long = 4
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
[/tt]
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Yeah that has solved it! Oh the joys of working on someone else's bad code!!
 
Another question, Alt225 - I can't find any place where hKey (the last variable passed to the API) is defined. How do I go about setting this? Is there a location I can seach for in the registry and if so, what would be the kind of thing I could search for?

It obviously differs each time so just a rough outline would be a lot of help!

;-)
 
just define hKey as long.

After calling the API function the first time with one of the consts HKEY, you get in hKey the handle to a subkey you searched for.

Now you can call the API again when hKey is the first parameter and the last one, too. This way you go "down" every time in the sub keys.

I hope I'm clear. If not - let me know.
 
So, if I get you correct, I do not need to assign a set value to HKey e.g hKey = 15000??

Just declare it as a long??
 
don't assign anything to it - just declare it.

hKey is a value that is passed ByRef, and it RETURNS the handle to the subkey you looked for.

The return code of the function itself is to determine if the function succeeded or not:

If the function succeeded the return code is 0 (ERROR_SUCCESS) and hKey has a non-zero value.

If the function fails the return code is a non-zero value which determines the error, and hKey will return 0.

End If :)
 
Howdy Naftali,
I have a user using our app on an "Active Directory" (Win 2K) set up and when logged in as a "Power User" the VB API call to RegOpenKeyEx doesn't seem to work for a key in "HKEY_LOCAL_MACHINE". It reads it fine when they log in as Admin.

Any Ideas?
 
i have alot of err in registry api so i just wrote a small ocx file that can manage all ur work in vb with registryit has about 54 functions and subs to make registry easy for me and i can gave it to any one may it help
but the way to use it is abit def from real api if u have ever write app in delphi u can do it in vb now
the ocx have not any interface (not yet) but still work ok in many function that i need at now
so any 1 here want it just email me and i will send it to u per email-until I complate it then upload it to my web site
me at
mhmbargouty@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top