Using RegConnectRegistry() with VB.net

  • Thread starter Thread starter Brian Patrick
  • Start date Start date
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
 
Brian,

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

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

Ken
 
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
 
Back
Top