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

x
?
Solved

writing to HKEY_LOCAL_MACHINE??

Posted on 1998-11-02
4
Medium Priority
?
416 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 390 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
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 …
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

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