Solved

RegConnectRegistry failure

Posted on 1998-12-02
2
753 Views
Last Modified: 2013-11-20
I'm trying to change a registry key in a remote machine's HKEY_LOCAL_MACHINE branch using RegConnectRegistry(). Everything's set up okay - both machines are NT4 servers (SP3) and Administrator account is set up so that it has full control over both machine A and machine B and full access to both registries.

Here's my code:

LPTSTR lpMachineName;      // address of name of remote computer
      lpMachineName = "\\SEURD01WEB002";

      HKEY hKey; // predefined registry handle
      hKey = HKEY_LOCAL_MACHINE;

      PHKEY phkResult; // address of buffer for remote registry handle
      
      LONG diditwork;
      diditwork = 0;
      
      diditwork = RegConnectRegistry(
                              lpMachineName,
                              hKey,
                              phkResult
                                          );                                          

      if (diditwork != ERROR_SUCCESS)
      
            MessageBox ("Remote connection failed");


Can you guys see anything wrong with this code ? I've performed the connection manually using regedt32 and connecting to the machine name and the branch - it works fine...

...so please, save me from going crazy and tell me what I'm doing wrong ! Thanks a lot,

Derek
0
Comment
Question by:der_bell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 170 total points
ID: 1325616
You aren't providing a place for the resultant HKEY to be stored, so you're passing the function an invalid pointer.
Try is this way:

LPTSTR lpMachineName; // address of name of remote computer
lpMachineName = "\\SEURD01WEB002";

HKEY hKey; // predefined registry handle
hKey = HKEY_LOCAL_MACHINE;

HKEY hkResult; // buffer for remote registry handle

LONG diditwork;
diditwork = 0;

diditwork = RegConnectRegistry(
lpMachineName,
hKey,
&hkResult
);
0
 

Author Comment

by:der_bell
ID: 1325617

Thanks a lot - it works fine when I make the amendment you suggest. I'm an idiot - I was looking in the wrong place for the error !

Derek
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question