Microsoft KB Archive/129532

MoveFileEx Not Supported in Windows 95 But Functionality Is

PSS ID Number: Q129532 Article last modified on 09-25-1995

4.00

WINDOWS

= SUMMARY =

Win32 applications running on Windows NT use MoveFileEx with the DELAY_UNTIL_REBOOT flag to move, replace, or delete the files currently being used. Examples of such files include device drivers and setup programs. To replace a file that is in use, you would do something like this:

MoveFileEx(szDstFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); MoveFileEx(szSrcFile, szDstFile, MOVEFILE_DELAY_UNTIL_REBOOT);

Windows 95 does not implement MoveFileEx but does provide an alternate way for all Win32-, Win16-, and MS-DOS-based applications to move, replace, or delete files that are currently in use. To replace a file that is in use, you would do something like this:

GetWindowsDirectory(szTmpName, cchpFullPathBuf); lstrcat(szTmpName, “\WININIT.INI”); WritePrivateProfileString(“Rename”, “NUL”, szDstFile, szTmpName); WritePrivateProfileString(“Rename”, szDstFile, szSrcFile, szTmpname);

= MORE INFORMATION =

Although Windows 95 does not implement MoveFileEx, it provides similar functionality to the DELAY_UNTIL_REBOOT flag through the [rename] section of WININIT.INI. If WININIT.INI is present in the Windows directory, WININIT.EXE processes it when the system boots. Once WININIT.INI has been processed, WININIT.EXE renames it to WININIT.BAK.

The syntax of the [rename] section is:

DestinationFileName=SourceFileName

NOTE: The source and destination filenames in WININIT.INI must be 8.3 file names. Long filenames are not processed.

The [rename] section can have multiple lines with one file per line. To delete a file, specify NUL as the DestinationFileName.

NOTE: DestinationFileName and SourceFileName cannot be long filenames, because WININIT.INI is processed before the protected mode disk system is loaded, and long filenames are only available when the protected mode disk system is running.

Here are some example entries:

[rename] NUL=C:.TXT C:_DIR.TXT=C:.TXT C:_DIR.TXT=C:.TXT C:.TXT=C:.TXT

The first line causes TEMP.TXT to be deleted. The second line causes EXISTING.TXT to be moved to a new directory. The third line causes OLDNAME.TXT to be moved and renamed. The fourth line causes an existing file to be overwritten by NEWFILE.TXT.

Applications should not use WritePrivateProfileString to write entries to the [rename] section because there can be multiple lines with the same DestinationFileName, especially if DestinationFileName is “NUL.” Instead, they should add entries by parsing WININIT.INI and appending them to the end of the [rename] section.

Applications that use WININIT.INI should check for its existence in the Windows directory. If WININIT.INI is present, then another application has written to it since the system was last restarted. Therefore, the application should open it, and add entries to the [rename] section. If WININIT.INI isn’t present, the application should create it and add to the [rename] section. Doing so ensures that entries from other applications won’t be deleted accidentally by your application.

NOTE: WININIT.INI is not processed until Windows 95 is restarted.

Additional reference words: 4.00 KBCategory: kbprg KBSubcategory: BseFileio ============================================================================= Copyright Microsoft Corporation 1995.