Microsoft KB Archive/193467

{|
 * width="100%"|

BUG: RegReplaceKey Fails in Windows 98

 * }

Q193467

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows 98

-

SYMPTOMS
The RegReplaceKey function is supposed to replace the file that backs a key and all its subkeys with another file. When the computer is restarted, the key and subkeys store the values in the new file. However, this

function might fail in Windows 98. The return value from RegReplaceKey might indicate that the call was successful, but the file might not be replaced when the computer is restarted.

CAUSE
Under Windows 98, the registry file is replaced during shutdown. This is a change from Windows 95, which replaced the registry file on start up. Under Windows 98, a message that notifies the system to replace the registry file is never sent if fast shutdown is enabled.

RESOLUTION
NOTE: This resolution only works with the original release of Windows 98 and not Windows 98 Second Edition. Currently, there is no workaround for Windows 98 Second Edition.

Disable fast shutdown by editing the FastReboot value in the registry.

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.

The following key contains a REG_SZ value named FastReboot:

  HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Shutdown

If this string is "1", fast shutdown is enabled. To disable fast shutdown, change the FastReboot value to "0".

If you use this resolution, you should probably restore the original value of FastReboot after you have successfully replaced the hive.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Steps to Reproduce Behavior
The following console application demonstrates the bug if fast shutdown is enabled:

  #include &lt;windows.h&gt; #include &lt;stdio.h&gt;

void main( void ) {

HKEY hKey, hNewKey; LONG lResult; char szTempfile1[MAX_PATH], szTempfile2[MAX_PATH];

lResult = RegOpenKey( HKEY_LOCAL_MACHINE, "Hardware", &hKey ); if ( lResult != ERROR_SUCCESS ) { printf( "RegOpenKey failed. Error %d\n", GetLastError ); } else {

printf( "Key opened\n" );

GetTempPath( MAX_PATH, szTempfile1 ); strcpy( szTempfile2, szTempfile1 ); strcat( szTempfile1, "TEMP.RG" ); strcat( szTempfile2, "TEMP.BK" );

lResult = RegSaveKey( hKey, szTempfile1, NULL ); if ( lResult != ERROR_SUCCESS ) { printf( "RegSaveKey failed. Error %d\n", GetLastError ); } else {

printf( "Key saved\n" );

lResult = RegCreateKey( HKEY_LOCAL_MACHINE, "TEMPKEY",              &hNewKey ); if ( lResult != ERROR_SUCCESS ) { printf( "RegCreateKey failed. Error %d\n",                 GetLastError ); } else {

printf( "Key created\n" ); RegCloseKey( hNewKey );

lResult = RegReplaceKey( HKEY_LOCAL_MACHINE, "TEMPKEY",                 szTempfile1, szTempfile2 ); if ( lResult != ERROR_SUCCESS ) { printf( "RegReplaceKey failed. Error %d\n",                    GetLastError ); } else { printf( "RegReplaceKey succeeded.\n" ); printf( "Restart the machine.\n" ); printf( "Use regedit to verify the changes.\n" ); }           }         }

RegCloseKey( hKey ); }

}

If successful, the program should create a copy of HKEY_LOCAL_MACHINE\HARDWARE under HKEY_LOCAL_MACHINE\TEMPKEY.

After you run the program, notice that the file SYSTEM.R is created in the WINDOWS directory. When you shutdown your computer, SYSTEM.DAT should be replaced by SYSTEM.R. However, if the Windows 98 fast shutdown is enabled, the file is never replaced.

NOTE: Manually renaming SYSTEM.R to SYSTEM.DAT is not supported. The system will not recognize the file as a valid registry hive.

After you run the previous sample code to verify the bug, you should delete the files TEMP.RG and TEMP.BK from the temporary directory. You should also delete the key TEMPKEY from the HKEY_LOCAL_MACHINE hive.

Additional query words:

Keywords : kbKernBase kbRegistry kbOSWin98bug

Issue type : kbbug

Technology : kbAudDeveloper kbWin32sSearch kbWin32API