all groups > vb.net > july 2003 >
You're in the

vb.net

group:

Using RegConnectRegistry() with VB.net


Using RegConnectRegistry() with VB.net Brian Patrick
7/29/2003 5:28:07 PM
vb.net:
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


Re: Using RegConnectRegistry() with VB.net Ken Tucker
7/29/2003 5:45:30 PM
Brian,

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

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

Ken

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

[quoted text, click to view]

Re: Using RegConnectRegistry() with VB.net Brian Patrick
7/29/2003 6:01:31 PM
Thanks very much!


[quoted text, click to view]

AddThis Social Bookmark Button