Solved

writing to HKEY_LOCAL_MACHINE??

Posted on 1998-11-02
4
365 Views
Last Modified: 2013-11-20
Using RegCreateKeyEx it seems that I cannot create a regestry key under HKEY_USERS or HKEY_LOCAL_MACHINE.  Is there a way to get around this problem?
If possible I'd like to steer away from CWinApp class members too.. - is this possible?

Tim
0
Comment
Question by:TimB
  • 2
4 Comments
 
LVL 3

Expert Comment

by:plaroche
ID: 1324163
What kinds of problems are you having?

I write to HKEY_LOCAL_MACHINE\Software quite easily and it works fine.  Are you under NT? If so have you checked that the logged user is administrator of the machine? I think it's needed to write to that registry section.
0
 

Accepted Solution

by:
gunn earned 130 total points
ID: 1324164
Try this function that I often use on WindowsNT/95/98, flawlessly ;)

-Tom

#define D_KEY "SOFTWARE\\Company\\WhateverElse"

char* GetRegKeyCT()

{

  long status;

  HKEY  hKey;

  DWORD type, datasize;

  BYTE *data;



  // Open the Key in the Windows Registry

  status = RegOpenKeyEx( HKEY_LOCAL_MACHINE,

                D_KEY,

                0,

                KEY_QUERY_VALUE,

                &hKey );



  // Check for error in opening

  if( status != ERROR_SUCCESS )

    return NULL;



  // Get the data size of the key first
   // "current_version" being the string you want to get...

  status = RegQueryValueEx( hKey, "current_version", NULL, &type, NULL, &datasize );

  if( datasize == 0 || status != ERROR_SUCCESS )

    return NULL;



  // Allocate the memory for the buffer then get the

  // data again, this time putting it into buffer.

  data   = (unsigned char*)malloc( (size_t)datasize );
   
   // "current_version" being the string you want to get...

  status = RegQueryValueEx( hKey, "current_version", NULL, &type, data, &datasize );



  // Check for error in obtaining data

  if( status != ERROR_SUCCESS )

    return NULL;



  // Close the open key

  status = RegCloseKey( hKey );



  return (char*)data;

}


0
 

Expert Comment

by:gunn
ID: 1324165
Ahhhhhhhhh, stupid me ;)

I read it, thinking 'ahh! I have done that!, only to (after posting the "answer") find out after reading -again- the question, that you were looking for way to *create* the key....doh!  I have done that too, but don't have the code at my fingertips....

sorry about that, you can reject my answer ;(

-Tom

0
 
LVL 1

Author Comment

by:TimB
ID: 1324166
Thanks for the help,  I figured out how to create a key under HKLM, I think it was just me not being able to understand mocrosoft help files - doh!

Here's what I did in the end:

RegCreateKeyEx(HKEY_LOCAL_MACHINE,      // handle of an open key
                  StrKeyPath, //  address of subkey name
                  0, // address of class string
                  NULL, // special options flag
                  0, //
                  KEY_SET_VALUE,  
                  NULL,
                  &hKey,
                          NULL) == ERROR_SUCCESS)


Thanks for your help anyway, and here's 130 points,

Bye-ee ;)

Tim
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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