Problem Reading/Writing Registry in Windows 7?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Problem Reading/Writing Registry in Windows 7?

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    21

    Problem Reading/Writing Registry in Windows 7?

    This may be in the wrong forum but here goes.

    I have a 32-bit application that I've been maintaining for about 12 years and it runs on every Windows platform up to Windows 7. In all that time I've been using CWinApp::GetProfileXxxx() and CWinApp::WriteProfileXxxx() calls to read and write my program settings (about 70 settings) in the Registry. The settings are read from the Registry at start-up and written to the Registry when the program closes. There is also a method for the user to read and write the program settings to an INI file using the same code as the Registry access.

    On my Windows 7 system the Registry read/write works just like it always has on all previous Windows versions. However, on some customer's Windows 7 machines there appears to be a problem with the Registry access. The program settings are either not being read from the Registry or are not being written to the Registry. I think the settings are not being written but I don't know that. When the user uses the INI file the settings appear to be read and written.

    The customer has complained a bit (I'd complain too) but doesn't have the time or doesn't want to take the time to run some simple tests for me to find out what's going on with his Windows 7 system.

    So here is my question: Are there any user account settings or permissions that can block the program's access to the Registry? He claims he is an Administrator but I can't even get him to verify that.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Problem Reading/Writing Registry in Windows 7?

    Quote Originally Posted by Mike Douglas View Post
    This may be in the wrong forum – but here goes.

    I have a 32-bit application that I've been maintaining for about 12 years and it runs on every Windows platform up to Windows 7.
    You must test your legacy apps separately on Windows 7, at least that is my experience. Since Windows 7 changed a lot around, you can't assume your app is compatible with Win 7.
    In all that time I've been using CWinApp::GetProfileXxxx() and CWinApp::WriteProfileXxxx() calls to read and write my program settings (about 70 settings) in the Registry.
    This is an example of the changes made.

    Windows 7 has more or less changed the way that the registry works. Look up "Registry Virtualization".

    Second, are you checking your return codes from your functions and calling GetLastError()? If so, what is the error you get when a registry function fails? You didn't mention this.

    Regards,

    Paul McKenzie

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,645

    Re: Problem Reading/Writing Registry in Windows 7?

    Try to use some of registry classes like CRegKey instead of these obsolete CWinApp::GetProfileXxxx() and CWinApp::WriteProfileXxxx() methods.

    BTW, do you check the return values of GetProfileXxxx / WriteProfileXxxx calles?
    Victor Nijegorodov

  4. #4
    Join Date
    Sep 2012
    Posts
    21

    Re: Problem Reading/Writing Registry in Windows 7?

    I did check my app in my Windows 7 machine and didn't have any problems with the GetProfileXxxx() and WriteProfileXxxx () Registry access calls. So like a moron I assumed that everything was OK.

    Again, like a moron I didn't check the return value of WriteProfileXxxx() because on my Win7 system it works. I think I'll go back and add a little 'check it' routine and check the return value to see what, if anything, is reported as an error. But, on my Win7 everything works so I'll have to figure out how to break it.

    I think the problem is related to the registry key permissions, but I'm not sure yet.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Problem Reading/Writing Registry in Windows 7?

    Quote Originally Posted by Mike Douglas View Post
    I did check my app in my Windows 7 machine and didn't have any problems with the GetProfileXxxx() and WriteProfileXxxx () Registry access calls. So like a moron I assumed that everything was OK.

    Again, like a moron I didn't check the return value of WriteProfileXxxx() because on my Win7 system it works. I think I'll go back and add a little 'check it' routine and check the return value to see what, if anything, is reported as an error. But, on my Win7 everything works so I'll have to figure out how to break it.
    Regardless whether if it works or not, you must check every return value when you call a Windows API, MFC, or any third-party library function that states that the function returns an error code. This is especially the case if your application is going to be used by customers who will be running your software on hardware you have no idea about.

    Your case is a classic example -- you don't know what hardware or software your users are running, how their systems are set up, etc. You never release an app that is meant to be used by the public and not check to make sure that every Windows call is valid. If an error occurs, then report the error with the combination of GetLastError() / FormatMessage() and a log file of some type.

    Without these checks, what winds up happening is that your assumption is wrong, and then your program takes the "everything is OK" path when everything is not OK, potentially causing damage. Can you imagine if your program was supposed to remove some registry keys, and that failure to check a return code caused some sort of memory corruption to a string variable, causing wrong keys to be removed?

    I once had to debug an app where a GDI call was failing and was never checked -- what wound up happening to one customer was that the ink out of a cheap inkjet printer would get used up due to totally black pages being outputted -- all assuming that a good image was being printed.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; February 19th, 2013 at 07:16 PM.

  6. #6
    Join Date
    Mar 2016
    Posts
    1

    Re: Problem Reading/Writing Registry in Windows 7?

    Mike I am hoping you got this resolved because I have a similar problem with our application. I also think it is related to registry key permission somehow.

  7. #7
    Join Date
    Sep 2012
    Posts
    21

    Re: Problem Reading/Writing Registry in Windows 7?

    Jeff,

    Never did find a satisfactory answer. The one customer that reported problems didn't want to help me find an answer. Sorry.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,273

    Re: Problem Reading/Writing Registry in Windows 7?

    Quote Originally Posted by Mike Douglas View Post
    Jeff,

    Never did find a satisfactory answer. The one customer that reported problems didn't want to help me find an answer. Sorry.
    Even if your customer is an administrator, depending on what keys your program writes to, the program itself may need to run as an administrator.

  9. #9
    Join Date
    Sep 2012
    Posts
    21

    Re: Problem Reading/Writing Registry in Windows 7?

    Hi Arjay,

    Shouldn't be a problem. I'm using HKEY_CURRENT_USER.

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,273

    Re: Problem Reading/Writing Registry in Windows 7?

    Quote Originally Posted by Mike Douglas View Post
    Hi Arjay,

    Shouldn't be a problem. I'm using HKEY_CURRENT_USER.
    Is the app a 32bit app, but the customer with the failure is running on a 64bit system?

  11. #11
    Join Date
    Sep 2012
    Posts
    21

    Re: Problem Reading/Writing Registry in Windows 7?

    Jeff,

    I thought about this after I posted my first reply today. One poster advised using CRegKey instead of WriteProfileXxxx() and ReadProfileXxxx() but CRegKey in my VC++6.0 doesn't have QueryBinaryValue() or SetBinaryValue() members and CRegKey is deprecated anyway (from what I've read). So I stayed with
    WriteProfileXxxx() and ReadProfileXxxx().

    During program initialization I used WriteProfileInt() to write a time value to the
    Registry, immediately read the value back with ReadProfileInt(), checked for a successful write, and made sure the value written was the same as the value read back. If the test failed then my program uses an INI file to save and restore its settings. I also notified the user but no one has said anything about it (yet). It's been about 3 years.

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,484

    Re: Problem Reading/Writing Registry in Windows 7?

    In case customer is not willing to cooperate, hardly you can do anything but testing on all possible platforms with all possible culture settings and be lucky enough to run into the same issue the customer really has. Taking this route or not, depends on your resources. And willing to help this particular customer who never responds to your requests.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center