如何在C / C ++中强制删除锁定的文件?

时间:2022-05-28 15:04:22

How do I programmatically force the deletion of files that are locked by the operating system or any other program with C/C++? The functionality should be similar to the software "Unlocker" at http://ccollomb.free.fr/unlocker.

如何以编程方式强制删除操作系统或任何其他程序使用C / C ++锁定的文件?该功能应类似于http://ccollomb.free.fr/unlocker上的软件“Unlocker”。

3 个解决方案

#1


5  

Look this sample.

看看这个样本。

#2


4  

If you are on Win32, the official way to do it is to mark it to be deleted on reboot, and ask the user to reboot. To mark the file to be deleted on reboot, use MoveFileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag (pass NULL as the destination).

如果您使用的是Win32,那么正式的方法是将其标记为在重新启动时删除,并要求用户重新启动。要在重新引导时标记要删除的文件,请使用带有MOVEFILE_DELAY_UNTIL_REBOOT标志的MoveFileEx(将NULL作为目标)。

#3


1  

This really depends on the underlying filesystem.

这实际上取决于底层文件系统。

For example, on Linux, ext3 supports file attributes that are not part of the standard unix read/write/execute/user/group/world paradigm.

例如,在Linux上,ext3支持的文件属性不属于标准的unix读/写/执行/用户/组/世界范例。

There is a nice summary of the available attributes here:

这里有一个很好的可用属性摘要:

Really drove me crazy the first time I came across, and even as root, and even after rebooting off a bottable CD I still couldn't delete a file off my hard drive... BTW, the possibilities for creative use of this for practical jokes are nearly endless... :)

我第一次遇到真的让我疯狂,甚至以root身份出现,甚至在重新启动可用的CD之后我还是无法删除我的硬盘驱动器上的文件...顺便说一下,创造性地使用这个实用程序的可能性笑话几乎无穷无尽...... :)

#1


5  

Look this sample.

看看这个样本。

#2


4  

If you are on Win32, the official way to do it is to mark it to be deleted on reboot, and ask the user to reboot. To mark the file to be deleted on reboot, use MoveFileEx with the MOVEFILE_DELAY_UNTIL_REBOOT flag (pass NULL as the destination).

如果您使用的是Win32,那么正式的方法是将其标记为在重新启动时删除,并要求用户重新启动。要在重新引导时标记要删除的文件,请使用带有MOVEFILE_DELAY_UNTIL_REBOOT标志的MoveFileEx(将NULL作为目标)。

#3


1  

This really depends on the underlying filesystem.

这实际上取决于底层文件系统。

For example, on Linux, ext3 supports file attributes that are not part of the standard unix read/write/execute/user/group/world paradigm.

例如,在Linux上,ext3支持的文件属性不属于标准的unix读/写/执行/用户/组/世界范例。

There is a nice summary of the available attributes here:

这里有一个很好的可用属性摘要:

Really drove me crazy the first time I came across, and even as root, and even after rebooting off a bottable CD I still couldn't delete a file off my hard drive... BTW, the possibilities for creative use of this for practical jokes are nearly endless... :)

我第一次遇到真的让我疯狂,甚至以root身份出现,甚至在重新启动可用的CD之后我还是无法删除我的硬盘驱动器上的文件...顺便说一下,创造性地使用这个实用程序的可能性笑话几乎无穷无尽...... :)