Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RegConnectRegistry failure

Posted on 1998-12-02
2
Medium Priority
?
771 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
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 680 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

927 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