Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 440681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:53:49+00:00 2026-05-12T20:53:49+00:00

I am playing with the registry programmatically for the first time, and it’s not

  • 0

I am playing with the registry programmatically for the first time, and it’s not working that well (but at least I haven’t destroyed my computer). Specifically, I keep getting back Error 5 (Access is Denied) from RegCreateKeyEx and RegSetValueEx. The thing that is strangest to me is that when HKEY_CURRENT_USER\Software\dir1\Sub Directory already exists, RegCreateKeyEx fails with Error 5, but when it doesn’t already exist, it creates it successfully; and then fails on the RegSetValueEx.

Am I doing anything wrong in this code?

BOOL MyDialog::SaveLocationsToRegistry()
{
    HKEY   hkey;
    DWORD  dwDisposition;
    DWORD dwType, dwSize;
    LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\dir1\\Sub Directory"), 
                                 0, NULL, 0, 0, NULL, &hkey, &dwDisposition);
    if(result == ERROR_SUCCESS)
    {
        LPCTSTR szLastFolder = "C:\\Documents and Settings\\user\\My Documents\\Copy of item\0";
        dwType = REG_SZ;
        dwSize = strlen(szLastFolder)+1;
        LONG setResult = RegSetValueEx(hkey, TEXT("LastFolder"), 0, dwType, 
        (PBYTE)&szLastFolder, dwSize);
        RegCloseKey(hkey);
        return setResult == ERROR_SUCCESS;
    }
    else
    {
        return false;
    }
}

Note: The absolute path is only there temporarily. Baby steps 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:53:50+00:00Added an answer on May 12, 2026 at 8:53 pm

    You’re not asking for any access rights. You probably want to specify KEY_WRITE (or something) for the 6th parameter (samDesired).

    LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\dir1\\Sub Directory"),
                     0, NULL, 0, KEY_WRITE, NULL, &hkey, &dwDisposition);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Playing with jquery for the first time, and I'm trying to get a simple
Playing with Disqus for commenting, but the problem is that we have a Silverlight
Playing around with the ReadArgs package , it seems that it does not support
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
While playing around with the emulator, I noticed that when trying to view a
Playing with a few tutorials on sockets but struggling to connect. My tomcat server
playing around with a property file i figured that there seems to be a
Playing with a Mobile application in ASP.NET MVC4 beta, using great that article ,
Im playing around with TryParse() But lets say the parsing fails, then returns false,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.