Go Windows restart delay removal, renaming technology principle

Source: Internet
Author: User
Tags knowledge base

The so-called restart delay removal technology is to delete or replace files before the operating system starts! Say lifting delay Delete, everyone may be very strange, but in fact, this feature has been adopted by various software: such as installing Windows patches (such as: HotFix, Service Pack), install Office patches, anti-virus software cleanup, software upgrades, File force removal Tool software, etc... This article begins with a description of how deferred deletion/renaming works, and then describes how to use this feature to maintain your system. I. What is restart delay Delete/Rename Many people may have encountered the following situation: When installing a software, the installer is initializing, suddenly, the installer pops up a warning prompt similar to the one described below: found that a restart operation is not completed, the installation process cannot continue before restarting the system. The installer then exits automatically. This type of hint occurs most often when you install Microsoft SQL Server. This hint occurs because the installer detects an incomplete restart. So how does the installer find an unfinished reboot? This is the point of this article: the deferred delete/rename feature of Windows 2000/xp/server 2003. For software developers, the delayed Delete/rename feature of Windows 2000/xp/server 2003 is nothing new, but the mechanism it implements is rarely noticed. This article does not want to involve much of the implementation mechanism inside windows, but simply describes the principle and scope of the deferred delete/rename feature of Windows 2000/xp/server 2003 from a single side. For Windows operating systems, to successfully delete a file or rename a file, one condition must be met: The file cannot be occupied. Sometimes, however, the file to be deleted/renamed is always occupied by a process, so the operator cannot delete and rename the file. To solve this problem, Microsoft proposed a deferred delete/rename function inside the Windows operating system. It is necessary to note that this feature exists not only in the Windows 2000/xp/server 2003 operating system, but also in the case of Windows 9X. But the focus of this article is to introduce the story of deferred deletion.

The basic implementation of deferred delete/rename is this: 1. If any application needs to use the deferred delete/rename feature, then the application uses a special parameter movefile_delay_until_reboot to command the Win32 API function MoveFileEx () to register a deferred delete in the system Rename operation. Registered records are placed in the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations And the PENDINGFILERENAMEOPERATIONS2 key value below. The key value is a key value of type REG_MULTI_SZ, and registry Editor cannot directly edit this type of key value. Warning! Do not use Registry Editor to directly edit this key value, which can cause the system to be unable to determine whether to perform a deferred delete operation or a deferred rename operation. 2. The next time the operating system is started, the above registry key value is read and analyzed by Smss.exe and the corresponding operation is completed. It is important to note that the WIN32 subsystem does not start when performing a deferred operation, which means that the deferred operation is done without the interference of the WIN32 subsystem. One of the biggest benefits of this design is that you can replace any files protected by the WIN32 subsystem. 3. If the above key value specifies that a file needs to be deleted, Smss.exe will perform the delete operation, and if the rename operation is specified, then Smss.exe performs the rename operation. Attention! If a file with the same name as the new file name exists when the rename operation is performed, the original file will be overwritten. For example: Suppose there is a file C:\1.DLL exists, and the delay rename inside the record is to rename C:\2.DLL to C:\1.DLL, then the original C:\1.DLL will be C:\2.DLL cover off. 4. When all the records are completed, the system automatically removes the above registry key values, and does not persist any traces. Now let's talk about how software developers use this feature. For example, install Windows Service Pack. After the service Pack installation is complete, the installer will definitely prompt the user to restart. In fact, the process of restarting is a process of performing deferred deletion/renaming. Since many files cannot be replaced by a new version of the file when the service Pack is installed, if this happens, the installer will rename the new version of the file and place it under the same directory as the old version file, and then register a deferred rename operation within the system. SystemAt the next boot time, the deferred rename operation will be performed to allow the old version of the file to be replaced by the new version file to complete the service Pack installation. For deferred deletion, it is similar to deferred renaming. If a file is found not to be deleted immediately, the software registers a deferred deletion, allowing the operating system to automatically delete the file the next time it is started.

For the deferred delete/rename feature, the software developer uses this feature for the following: & #1048698; Replacement & #1048698 of new version files; Delete files that cannot be deleted immediately for general users, when do you need this feature? & #1048698; Cannot rename a file & #1048698 that is always occupied by a process; A file could not be deleted. Especially when you want to delete a computer virus body file. In both cases, you can use the deferred action to let the operating system do what you want. Go back and talk about how the installer found a reboot that was done by an unfinished program. Because the deferred operation is logged under the registry-specific key value, it is only necessary to detect a specific key value to discover an unfinished restart operation.

MoveFileEx (Szdstfile, NULL, movefile_delay_until_reboot); MoveFileEx (szSrcFile, Szdstfile, movefile_delay_until_reboot);

Movefile_delay_until_reboot:

The system does not move the file until the operating system is restarted. The system moves the file immediately after AUTOCHK are executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from previous startups.

This value can being used only if the process was in the context of a user who belongs to the Administrators group or the Loca Lsystem account.

This value cannot is used with movefile_copy_allowed.

Windows Server 2003 and Windows XP: For information about special situations where this functionality can FA Il, and a suggested workaround solution, see "Files is not exchanged when Windows Server 2003 restarts if your use the Mov Efileex function to schedule a replacement for some files ' in the ' Help ' and ' support ' knowledge Base at Http://support.micros oft.com/kb/948601.
Windows: If You specify the MOVEFILE_DELAY_UNTIL_REBOOT flag for dwFlags, you cannot also PR Epend The file name is specified by lpexistingfilename with "\ \".

Go Windows restart delay removal, renaming technology principle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.