Is it possible to delete a file that is opened by a process under windows?

For testing and simulation purposes I would like to delete a file that is currently open by my process.

The CreateFile docs state that it is possible to open a file in a mode (FILE_SHARE_DELETE) that allows the file the open handle is pointing to to be deleted by another operation. (And I already tried and confirmed this via CreateFile(FILE_SHARE_DELETE) + DeleteFile.)

What I would like to know now however is, whether it is possible at all that a file that is opened by anyone without above mentioned flag to be deleted somehow?

As far as I understand the DeleteFile docs it would not be possible with this functions, as

The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.

Is there any other way to delete a file that is open, but does not have the FILE_SHARE_DELETE flag set?


There is no way to do this.

The closest way to do something like this is to schedule delete on reboot using MoveFileEx with a target filename of NULL, and MOVEFILE_DELAY_UNTIL_REBOOT in the dwFlags parameter.

Need Your Help

Django Celery causes an import error on runserver command

python django celery importerror

When I issue a runserver command, an ImportError is raised from djcelery (Django Celery).

AS3 removing all children from array in a class from parent class

actionscript-3 oop actionscript

In the Level 1 class (Parent) I generate citizens as seperate objects (c) to walk from left or right across the stage. all of these get added to an array called citizens:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.