Solved

writing to HKEY_LOCAL_MACHINE??

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
mixString challenge 36 111
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 89
sum28 challenge 31 105
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

14 Experts available now in Live!

Get 1:1 Help Now