Windows 95 and Windows NT provide a unique way to help applications delete, replace, or rename the files and directories being used. Although these two platforms have different ways, they have a common overall strategy that specifies files to be processed by the application, and then the system processes these files when restarting. This article explains how the application uses the methods provided by each Windows platform. MORE INFORMATION Mobile files running on Windows NT Based on WIN32-based applications should be used in conjunction with the MoveFileEx () and MoveFile_Delay_until_reboot flags to move, replace or delete the files and directories currently being used. When restarting the system next time, the Windows NT startup program will move, replace or delete the specified files and directories.
To move or replace the file or directory being used, the application must specify the source path and target path on the same volume (for example, drive C :). If the target path is an existing file, it will be overwritten. If the target path is an existing directory, it will not be overwritten and the source path and the target path will remain unchanged. Here is a call example of a mobile or replacement file or a mobile directory: //move szsrcfile to szdstfile next time system is rebooted MoveFileEx (szsrcfile, szdstfile, movefile_delay_until_reboot); To delete a file or directory, the application must set the target path to NULL. If the source path is a directory, only it can be deleted when it is empty. Note that if you must use MoveFileEx () to remove the file from a directory, you must restart your computer before calling MoveFileEx () to delete the directory. Here is an example of how to delete a sample file or empty directory: // Delete szSrcFile next time system is rebooted MoveFileEx (szSrcFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); in Windows 95 to move files Windows 95 does not implement MoveFileEx (), but it is all based on Win32, A method of moving, replacing or deleting a file (but not a directory) currently being used, replaced or deletes the currently being used. This feature is implemented by the [Rename] section of the file named Wininit.ini. If you have a Wininit.ini file in the Windows directory, Wininit.exe will process the file when the system is started. After processing Wininit.ini, Wininit.exe will rename it as Wininit.bak.
The syntax of the [Rename] is as follows: DestinationFileName = SourceFileName DestinationFileName and SourceFileName must be on the same volume and must be a short (8.3) file name, because wininit.ini is processed before the disk system is loaded, and the long file name is only The disk system of the protection mode is running. The target and source files specified in Wininit.ini are ignored.
[Rename] section can contain multiple lines, one file per line. To delete a file, specify DestinationFileName as NUL. Here are some examples: [Rename] NUL = C: /TEMP.TXT C: /NEW_DIR/EXISTING.TXT =c: /existing.txt c: /new_dir/newname.txt=c: /oldname.txt C: /EXISTING.TXT=C:/Temp/newFile.txt The first row deletes Temp.txt. The second line moves existing.txt to a new directory. The third line moves and renames OldName.txt. The fourth line is covered with newfile.txt overwrites existing documents. The application cannot use WritePrivateProfileString () to write the item [Rename], because there may be multiple rows with the same DestinationFileName, especially when DestinationFileName is "NUL". Instead, add items should be added by analyzing Wininit.ini and adding each item to the end of the [Rename] section.
Note: Always use uncarded search to analyze WininIt.ini because the title of [Rename] and the file names therein may contain any combination of case letters.
The application that uses WininIt.ini should check if the file exists in the Windows directory. If WininiT.ini is present, the other application has written to the file since the system is restarted. Therefore, the application should open the file and add an item to the [Rename] section. If WininIt.ini does not exist, the application should create the file and add an item to the [Rename] section. Doing so ensures that your application does not intend to delete items written in other applications.
To undo the file rename operation before system restart, you must delete the corresponding row from the [Rename] section of the WinInit.ini file.