The RegConnectRegistry function establishes a connection to a predefined registry key on another computer.
LONG RegConnectRegistry(
LPCTSTR lpMachineName,
HKEY hKey,
PHKEY phkResult
);
Parameters
lpMachineName
[in] Pointer to a null-terminated string specifying the name of the remote computer. The string has the following form:
//computername
The caller must have access to the remote computer or the function fails.
If this parameter is NULL, the local computer name is used.
hKey
[in] Predefined registry handle. This parameter can be one of the following predefined keys on the remote computer.
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_PERFORMANCE_DATA
HKEY_USERS
Windows Me/98/95: This parameter can also be one of the following values:
HKEY_CURRENT_CONFIG
HKEY_DYN_DATA
phkResult
[out] Pointer to a variable that receives a key handle identifying the predefined handle on the remote computer.
Return Values
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
Remarks
When a handle returned by RegConnectRegistry is no longer needed, it should be closed by calling RegCloseKey.
If the computer is joined to a workgroup and the "Force network logons using local accounts to authenticate as Guest" policy is enabled, the function fails. Note that this policy is enabled by default if the computer is joined to a workgroup.
If the current user have not have proper access to the remote computer, the call to RegConnectRegistry fails. One possible workaround is to establish a session to an administrative share such as IPC$ using a different set of credentials. To specify credentials other than those of the current user, use the WNetAddConnection2 function to connect to the share. When you have finished accessing the registry, cancel the connection.
Windows XP Home Edition: You cannot use this function to connect to a remote computer running Windows XP Home Edition. This function does work with the name of the local computer even if it is running Windows XP Home Edition because this bypasses the authentication layer.
Windows Me/98/95: To use RegConnectRegistry, you must install the Microsoft Remote Registry service. If you don't do this, calls to RegConnectRegistry return ERROR_DLL_INIT_FAILED. Perform the following steps to install the Microsoft Remote Registry service.
To install the Microsoft Remote Registry service
In the Network option in Control Panel, click Add.
In the Select Network Component Type dialog box, double-click Service.
In the Select Network Service dialog box, click the Have Disk button.
In the Install From Disk dialog box, type the path to the ADMIN/NETTOOLS/REMOTREG directory on the Windows 95 compact disc, and then click OK.
In the Install From Disk dialog box, click OK.
In the Select Network Service dialog box, click Microsoft Remote Registry, and then click OK.
If you are prompted to specify the location of additional files, specify the path to the files on a shared network directory or on the compact disc.
Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Unicode: Implemented as RegConnectRegistryW(Unicode) and RegConnectRegistryA(ANSI).
Header: Declared in Winreg.h; include Windows.h.
Library: Use Advapi32.lib.
DLL: advapi32.dll