Article ID: 193467
Article Last Modified on 11/21/2006
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.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Shutdown
#include <windows.h>
#include <stdio.h>
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 );
}
}
Keywords: kbbug kbkernbase kbnofix kbregistry KB193467