CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Windows SDK Registry: How can I write data to the registry?

    Q: How can I write data to the registry?

    A:

    Code:
    HKEY hKey;
    
    if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                      "System\\CurrentControlSet\\Control\\Windows",
                      0,
                      KEY_SET_VALUE,
                      &hKey) == ERROR_SUCCESS)
    {
      DWORD dwValue = 245;
    
      // Set value
      if(::RegSetValueEx(hKey,
                         "NameOfValue",
                         0,
                         REG_DWORD,
                         reinterpret_cast<BYTE *>(&dwValue),
                         sizeof(dwValue)) != ERROR_SUCCESS)
      {
        // Close key
        ::RegCloseKey(hKey);
    
        // Error handling;
      }
    
      // Close key
      ::RegCloseKey(hKey);
    }
    else
      // Error handling;
    Last edited by Andreas Masur; July 25th, 2005 at 03:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured