#include <windows.h> #include <ntdll.h> int WINAPI iWinMain() { #ifdef _WIN64 LPWSTR captionMsg = L"64-bit Application"; #else LPWSTR captionMsg = L"32-bit Application"; #endif LPWSTR finishedMsg = L"Failed!"; NTSTATUS ntStatus; HANDLE FileHandle; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING ObjectName; IO_STATUS_BLOCK IoStatusBlock; RtlInitUnicodeString(&ObjectName, L"\\??\\c:\\test.txt"); InitializeObjectAttributes( &ObjectAttributes, &ObjectName, OBJ_CASE_INSENSITIVE, NULL, NULL); if (NtOpenFile( &FileHandle, DELETE, &ObjectAttributes, &IoStatusBlock, 0, FILE_DELETE_ON_CLOSE) == STATUS_SUCCESS) { if (NtClose(FileHandle) == STATUS_SUCCESS) { MessageBoxW( NULL, L"Done...\nFile:\"C:\\test.txt\" deleted.", captionMsg, MB_ICONINFORMATION); finishedMsg = L"Finished!"; } } MessageBoxW( NULL, finishedMsg, captionMsg, MB_ICONINFORMATION); return 0; }
Source:
http://www.mediafire.com/download/eqe09020m829lmv/FileDeleteOnClose.rar