Registry Access

This is a discussion on Registry Access within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I'm having problems with the registry.. and the Win32 API Reference isn't exactly clear. Say I wanted to greet ...

  1. #1
    Registered User ExDigit's Avatar
    Join Date
    Jan 2002
    Posts
    31

    Question Registry Access

    Hello,
    I'm having problems with the registry.. and the Win32 API Reference isn't exactly clear.
    Say I wanted to greet the user by the name stored in the registry, located at:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion

    The data value that I want to read is "RegisteredOwner" - after this I would simply display a message box.

    Also, how can I set a value in the registry? I can use RegSetValue but that only stores data in the registry as the "default" data value - perhaps I want to store a value in the registry under a certain key with the string value name of "User".. To put this in more simple terms, I wish to achieve the same effect as the following ".key" file:

    REGEDIT4

    [HKEY_LOCAL_MACHINE\Software\MySoftware]
    "UserName"="Bill Gates"
    "RegistrationKey"="G45-46346-DF345"


    Any tutorials or replies helping with this problem would be gratefully appreciated.

    Thanks.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    To access the data you open the key and then query the value -

    Code:
    	HKEY hkey;
    	TCHAR name[255];
    	TCHAR sk[] = "Software\\Microsoft\\Windows\\CurrentVersion";
    	DWORD a;
    	DWORD b;
    	RegOpenKeyEx(HKEY_LOCAL_MACHINE,sk,0,KEY_QUERY_VALUE ,&hkey);
    	RegQueryValueEx(hkey,"Registered Owner",0,&a,(BYTE*)name,&b);
    	MessageBox(0,name,"Hello",0);
    I think you could probably do something similar to write to data to a key using RegSetValueEx(). However you'll need to adjust the access when opening the key, and ensure the person using your program has admin rights on NT based Windows.

    From your example I'd guess it'd be something like this -

    Code:
    	TCHAR dataname[]="UserName";
    	TCHAR data[]="Bill Gates";
    	RegSetValueEx(hkey,dataname,0,REG_SZ,(BYTE*)data,strlen(data)+1);
    Assuming you'd already opened the HKEY_LOCAL_MACHINE\Software\MySoftware with the required access using RegOpenKeyEx(). This is untested so you may have to changed it around to get the required result.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post That won't work for me...

    I checked everything to make sure it's correct in my registry. I had the same Q but never got to post it. When I did:


    HKEY hkey;
    TCHAR name[255];
    TCHAR sk[] = "Software\\Microsoft\\Windows\\CurrentVersion" ;
    DWORD a;
    DWORD b;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE,sk,0,KEY_QUERY_VAL UE ,&hkey);
    RegQueryValueEx(hkey,"RegisteredOwner",0,&a,(BYTE* )name,&b);
    MessageBox(0,name,"Owner",0);


    It comes up with a message box, it's just blank.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I checked everything to make sure it's correct in my registry. I had the same Q but never got to post it. When I did:


    HKEY hkey;
    TCHAR name[255];
    TCHAR sk[] = "Software\\Microsoft\\Windows\\CurrentVersion" ;
    DWORD a;
    DWORD b;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE,sk,0,KEY_QUERY_VA
    LUE ,&hkey);
    RegQueryValueEx(hkey,"RegisteredOwner",0,&a,(BYTE* )name,&b);
    MessageBox(0,name,"Owner",0);


    It comes up with a message box, it's just blank
    It will work in Windows 98, but that specific key isnt in that position on Win2K for instance.

    The registries of Win2K+ and 95/98 are very different

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Requested registry access is not allowed
    By arby220 in forum C# Programming
    Replies: 1
    Last Post: 06-24-2009, 12:57 AM
  2. Registry, Regedit
    By franse in forum C++ Programming
    Replies: 21
    Last Post: 01-29-2009, 08:57 AM
  3. access to devices
    By pastitprogram in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2008, 11:16 PM
  4. Access denied on adding another registry value
    By BobS0327 in forum Windows Programming
    Replies: 0
    Last Post: 01-09-2006, 07:10 PM
  5. Direct disk access in DOS
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-26-2002, 01:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21