How does Windows remove locked files in the next reboot when you uninstall a program? Maybe with some kind of scheduled process?
1 Answers
The uninstall process uses MoveFileEx
with the MOVEFILE_DELAY_UNTIL_REBOOT
flag set, which indicates that the operation shouldn't occur until reboot. Leaving the lpNewFileName
parameter NULL indicates the file should be deleted:
If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx registers the lpExistingFileName file to be deleted when the system restarts. If lpExistingFileName refers to a directory, the system removes the directory at restart only if the directory is empty.
The info on MOVEFILE_DELAY_UNTIL_REBOOT
says:
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 is executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from previous startups
The above function writes an entry to the registry which is automatically processed during startup:
The function stores the locations of the files to be renamed at restart in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

- 123,280
- 14
- 225
- 444
-
That's on the Desktops and Servers. Windows CE and Windows Mobile does not have the APIs or behaviors. (Windows CE is still popular because of the medical field and the certification process surrounding devices). I'm not sure of Windows Phone since I've never encountered it. – jww Feb 08 '14 at 02:28
-
@noloader: Do CE and Mobile have uninstallers that delay file removal until the device is restarted? I admit I don't currently have a CE or Windows Mobile device, but I've never seen one that deferred file removal until a reboot. If it's never needed, that would explain why it doesn't exist on those platforms. – Ken White Feb 08 '14 at 02:35