Solved

writing to HKEY_LOCAL_MACHINE??

Posted on 1998-11-02
4
388 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
[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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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: 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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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