Platform SDK: Registry

RegConnectRegistry

The RegConnectRegistry function establishes a connection to a predefined registry handle on another computer.

LONG RegConnectRegistry(
  LPCTSTR lpMachineName, // computer name
  HKEY hKey,             // predefined registry handle
  PHKEY phkResult        // buffer for remote key handle
);

Parameters

lpMachineName
[in] Pointer to a null-terminated string specifying the name of the remote computer. The string has the following form:

\\computername

If lpMachineName is NULL, the local computer name is used.

hKey
[in] Specifies the one of the following predefined registry handles on the remote computer.

HKEY_LOCAL_MACHINE
HKEY_USERS

Windows NT/2000: HKEY_PERFORMANCE_DATA, if the remote computer is running Windows NT/Windows 2000

Windows 95/98: HKEY_DYN_DATA, if the remote computer is running Windows 95 or Windows 98.HKEY_CURRENT_CONFIG, if the remote computer is running Windows 95 or Windows 98.

You cannot specify the HKEY_CLASSES_ROOT or HKEY_CURRENT_USER value for this parameter.

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.

Windows 95/98: No registry subkey or value name may exceed 255 characters.

Windows 95: To use RegConnectRegistry on Windows 95, 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

  1. In the Network option in Control Panel, click Add.
  2. In the Select Network Component Type dialog box, double-click Service.
  3. In the Select Network Service dialog box, click the Have Disk button.
  4. 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.
  5. In the Install From Disk dialog box, click OK.
  6. 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 Windows 95 source files on a shared network directory or on the Windows 95 compact disc.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winreg.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Registry Overview, Registry Functions, RegCloseKey