

- Messages
- 2,467
- Location
- Bamberg Germany
I've been noticing lately a lot of people have been asking "Why is disk cleanup taking so long???". Some people seen to think Windows just deletes them right away or marks the file for deletion, but there is a little more involved than that, especially for kernel changes such as the updates on Patch Tuesday. Files in use must be flagged, replaced, copied, moved delayed to a temp file, written, and renamed. I'm sure many have seen this term: PendingFileRenameOperations. This must happens to all "in use" files be it drivers, windows defender, and Windows Updates(which should be kept awhile incase of needed rollback or uninstallation) no matter how small or large, it can be a lot and for the cpu(be it a B960 or an i7) it takes time to do.
I finally found a bit of code HERE that shows what happens:
///
/// Consts defined in WINBASE.H
///
internal enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 1,
MOVEFILE_COPY_ALLOWED = 2,
MOVEFILE_DELAY_UNTIL_REBOOT = 4,
MOVEFILE_WRITE_THROUGH = 8
}
///
/// Marks the file for deletion during next system reboot
///
///
The current name of the file or directory on the local computer.
///
The new name of the file or directory on the local computer.
///
MoveFileFlags
/// bool
/// MoveFileEx function (Windows)
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll",EntryPoint="MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName,
MoveFileFlags dwFlags);
//Usage for marking the file to delete on reboot
MoveFileEx(fileToDelete, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);The file is marked for deletion in registry in following location
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerPendingFileRenameOperations
I hope this helps and if anyone else can correct or add to this it would be appreciated.
I finally found a bit of code HERE that shows what happens:
///
/// Consts defined in WINBASE.H
///
internal enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 1,
MOVEFILE_COPY_ALLOWED = 2,
MOVEFILE_DELAY_UNTIL_REBOOT = 4,
MOVEFILE_WRITE_THROUGH = 8
}
///
/// Marks the file for deletion during next system reboot
///
///
The current name of the file or directory on the local computer.
///
The new name of the file or directory on the local computer.
///
MoveFileFlags
/// bool
/// MoveFileEx function (Windows)
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll",EntryPoint="MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName,
MoveFileFlags dwFlags);
//Usage for marking the file to delete on reboot
MoveFileEx(fileToDelete, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);The file is marked for deletion in registry in following location
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerPendingFileRenameOperations
I hope this helps and if anyone else can correct or add to this it would be appreciated.