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

Thread: Problem Reading/Writing Registry in Windows 7?

  1. #1
    Join Date
    Sep 2012
    Posts
    14

    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,426

    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
    17,360

    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
    14

    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,426

    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
    Feb 2013
    Posts
    1

    Re: Problem Reading/Writing Registry in Windows 7?

    I always check out this website before downloading registry software for pc/mac - www.microsoftapple.com - My personal favourite is smart pc fixer because it's just incredibly simple to use and does exactly what it's name suggests. A good mac alternative is detox my mac for similar reasons.

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center