Solved

RegConnectRegistry failure

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now