Solved

RegConnectRegistry failure

Posted on 1998-12-02
2
743 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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