Using RegConnectRegistry() with VB.net

B

Brian Patrick

I cannot seem to get the following code to work in VB.net:

----------------------------------------------------------------------------
-------------------------
Const HKEY_LOCAL_MACHINE = &H80000002

Declare Function RegConnectRegistry Lib "advapi32.dll" Alias
"RegConnectRegistryA" _
(ByVal lpMachineName As String, ByVal hKey As Int32, ByVal phkResult As
Int32) As Int32

(the code below would be placed in a sub or function)
Dim lReturnCode as Int32
Dim lhRemoteRegistry as Int32

lReturnCode = RegConnectRegistry("\\MyMachine", HKEY_LOCAL_MACHINE,
lhRemoteRegistry)

----------------------------------------------------------------------------
-------------------------

lReturnCode always returns 1780, when it should be returning zero. If I
take this same code and copy it into a VB 6 project (changing the Int32's to
Long's of course) it works perfectly and connects to the remote registry.

Any ideas?

Thanks,
Brian
 
K

Ken Tucker

Brian,

Use the registry class instead of the API.
Dim rKey As Microsoft.Win32.RegistryKey

rKey =
Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
\\MyMachine)

Ken
 
B

Brian Patrick

Thanks very much!


Ken Tucker said:
Brian,

Use the registry class instead of the API.
Dim rKey As Microsoft.Win32.RegistryKey

rKey =
Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
\\MyMachine)

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top