locked
Is Windows 7 registry vollatile? RRS feed

  • Question

  • I have an application that saves some important data in the Windows Registry. This data is used when the system is restarted. The exact flow is as follows:

    1. The application is started for the first time.
    2. It writes some important configuration data of the current operation in the registry.
    3. The operation runs regularly until there is a failure (which can be the application process is ended, the computer is restarted or the power is down and the computer turns off).
    4. When the operation is restablished (after the computer restarts, in case it was turned off), it gets the configuration data from the registry and restarts the operation based on it.

    This operation flow worked for many years without any problem at all. However, a few months ago, we had to update our OS from XP to Windows 7, and it suddenly stopped working for the power down case. This means that if the computer was manually restarted or the process ended suddenly, it was able to recover the configuration from the registry. However if the computer was turned off due to a power failure, the registry was not holding the writen value, and the configuration data was empty.

    I am suspicious that Windows 7 registry is kind of vollatile. Which means that when we write in the registry from inside the application, this new key value is written in memory, and just stored in the hard disk when the Windows shut up process runs. If it were a database, we could say that a section was started and it was only committed when the shut down process was running. In case the computer is turned off without running this process, the section closed and the changes suffered a rollback.

    Is it a Windows 7 issue? Is there a way of "forcing" the commit inside the application code? Am I correct in my diagnose?

    Thank you.

    Monday, June 4, 2012 6:42 PM

Answers

  • Two things we should pay attention to in Windows 7 registry operation,

    1. Windows 7 only allow the administrator operate the registry, so did you run your application as Admin? If not, try to Run as Admin, or configurate one manifest to requireAdministrator for your application in default: http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx Or you could choose run your application still in one compatibility mode, such as XP.

    2. If it is one 32-bit application and run in one 64-bit OS, Windows Registry will map the registries to HLC\SOFTWARE\Wow6432Node. Refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx

    So could you please provide where your data and vlaue store in registry, how to write and read the registry in your code.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jie Bao Tuesday, June 12, 2012 6:02 AM
    Wednesday, June 6, 2012 6:50 AM
  •  

    RegFlushKey

    Writes all the attributes of the specified open registry key into the registry.

    LONG RegFlushKey(
      HKEY hKey
    );
    

    Parameters

    hKey
    [in] A handle to an open registry key. The key must have been opened with the KEY_QUERY_VALUE access right. For more information, see Registry Key Security and Access Rights.

    This handle is returned by the RegCreateKeyEx, RegCreateKeyTransacted, RegOpenKeyEx, or RegOpenKeyTransacted function. It can also be one of the following predefined keys:

    HKEY_CLASSES_ROOT
    HKEY_CURRENT_CONFIG
    HKEY_CURRENT_USER
    HKEY_LOCAL_MACHINE
    HKEY_PERFORMANCE_DATA
    HKEY_USERS

    Windows Me/98/95:  This parameter can also be the following value:

    HKEY_DYN_DATA

    Return Value

    If the function succeeds, the return value is ERROR_SUCCESS.

    If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the <?XML:NAMESPACE PREFIX = MSHelp NS = "http://msdn.microsoft.com/mshelp" /><MSHelp:link tabIndex=0 errorURL="../common/badjump.htm" keywords="_win32_formatmessage">FormatMessage</MSHelp:link> function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

    Remarks

    It is not necessary to call RegFlushKey to change a key. Registry changes are flushed to disk by the registry using its lazy flusher. Lazy flushing occurs automatically and regularly after a system-specified interval of time. Registry changes are also flushed to disk at system shutdown.

    Unlike RegCloseKey, the RegFlushKey function returns only when all the data has been written to the registry.

    The RegFlushKey function may also write out parts of or all of the other keys. Calling this function excessively can have a negative effect on an application's performance.

    An application should only call RegFlushKey if it requires absolute certainty that registry changes are on disk. In general, RegFlushKey rarely, if ever, need be used.


    --
    .
    --
    "JPNavarini" wrote in message news:70c69b82-fb5a-4efe-8613-75ea9c022f32...
    >I have an application that saves some important data in the Windows Registry. This data is used when the system is restarted. The exact flow is as follows:
    >
    >  1.. The application is started for the first time.
    >  2.. It writes some important configuration data of the current operation in the registry.
    >  3.. The operation runs regularly until there is a failure (which can be the application process is ended, the computer is restarted or the power is down and the computer turns off).
    >  4.. When the operation is restablished (after the computer restarts, in case it was turned off), it gets the configuration data from the registry and restarts the operation based on it.
    > This operation flow worked for many years without any problem at all. However, a few months ago, we had to update our OS from XP to Windows 7, and it suddenly stopped working for the power down case. This means that if the computer was manually restarted or the process ended suddenly, it was able to recover the configuration from the registry. However if the computer was turned off due to a power failure, the registry was not holding the writen value, and the configuration data was empty.
    >
    > I am suspicious that Windows 7 registry is kind of vollatile. Which means that when we write in the registry from inside the application, this new key value is written in memory, and just stored in the hard disk when the Windows shut up process runs. If it were a database, we could say that a section was started and it was only committed when the shut down process was running. In case the computer is turned off without running this process, the section closed and the changes suffered a rollback.
    >
    > Is it a Windows 7 issue? Is there a way of "forcing" the commit inside the application code? Am I correct in my diagnose?
    >
    > Thank you.
    >
    • Marked as answer by Jie Bao Tuesday, June 12, 2012 6:02 AM
    Wednesday, June 6, 2012 7:35 AM

All replies

  • Two things we should pay attention to in Windows 7 registry operation,

    1. Windows 7 only allow the administrator operate the registry, so did you run your application as Admin? If not, try to Run as Admin, or configurate one manifest to requireAdministrator for your application in default: http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx Or you could choose run your application still in one compatibility mode, such as XP.

    2. If it is one 32-bit application and run in one 64-bit OS, Windows Registry will map the registries to HLC\SOFTWARE\Wow6432Node. Refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx

    So could you please provide where your data and vlaue store in registry, how to write and read the registry in your code.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jie Bao Tuesday, June 12, 2012 6:02 AM
    Wednesday, June 6, 2012 6:50 AM
  •  

    RegFlushKey

    Writes all the attributes of the specified open registry key into the registry.

    LONG RegFlushKey(
      HKEY hKey
    );
    

    Parameters

    hKey
    [in] A handle to an open registry key. The key must have been opened with the KEY_QUERY_VALUE access right. For more information, see Registry Key Security and Access Rights.

    This handle is returned by the RegCreateKeyEx, RegCreateKeyTransacted, RegOpenKeyEx, or RegOpenKeyTransacted function. It can also be one of the following predefined keys:

    HKEY_CLASSES_ROOT
    HKEY_CURRENT_CONFIG
    HKEY_CURRENT_USER
    HKEY_LOCAL_MACHINE
    HKEY_PERFORMANCE_DATA
    HKEY_USERS

    Windows Me/98/95:  This parameter can also be the following value:

    HKEY_DYN_DATA

    Return Value

    If the function succeeds, the return value is ERROR_SUCCESS.

    If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the <?XML:NAMESPACE PREFIX = MSHelp NS = "http://msdn.microsoft.com/mshelp" /><MSHelp:link tabIndex=0 errorURL="../common/badjump.htm" keywords="_win32_formatmessage">FormatMessage</MSHelp:link> function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

    Remarks

    It is not necessary to call RegFlushKey to change a key. Registry changes are flushed to disk by the registry using its lazy flusher. Lazy flushing occurs automatically and regularly after a system-specified interval of time. Registry changes are also flushed to disk at system shutdown.

    Unlike RegCloseKey, the RegFlushKey function returns only when all the data has been written to the registry.

    The RegFlushKey function may also write out parts of or all of the other keys. Calling this function excessively can have a negative effect on an application's performance.

    An application should only call RegFlushKey if it requires absolute certainty that registry changes are on disk. In general, RegFlushKey rarely, if ever, need be used.


    --
    .
    --
    "JPNavarini" wrote in message news:70c69b82-fb5a-4efe-8613-75ea9c022f32...
    >I have an application that saves some important data in the Windows Registry. This data is used when the system is restarted. The exact flow is as follows:
    >
    >  1.. The application is started for the first time.
    >  2.. It writes some important configuration data of the current operation in the registry.
    >  3.. The operation runs regularly until there is a failure (which can be the application process is ended, the computer is restarted or the power is down and the computer turns off).
    >  4.. When the operation is restablished (after the computer restarts, in case it was turned off), it gets the configuration data from the registry and restarts the operation based on it.
    > This operation flow worked for many years without any problem at all. However, a few months ago, we had to update our OS from XP to Windows 7, and it suddenly stopped working for the power down case. This means that if the computer was manually restarted or the process ended suddenly, it was able to recover the configuration from the registry. However if the computer was turned off due to a power failure, the registry was not holding the writen value, and the configuration data was empty.
    >
    > I am suspicious that Windows 7 registry is kind of vollatile. Which means that when we write in the registry from inside the application, this new key value is written in memory, and just stored in the hard disk when the Windows shut up process runs. If it were a database, we could say that a section was started and it was only committed when the shut down process was running. In case the computer is turned off without running this process, the section closed and the changes suffered a rollback.
    >
    > Is it a Windows 7 issue? Is there a way of "forcing" the commit inside the application code? Am I correct in my diagnose?
    >
    > Thank you.
    >
    • Marked as answer by Jie Bao Tuesday, June 12, 2012 6:02 AM
    Wednesday, June 6, 2012 7:35 AM