Created
March 9, 2018 10:49
-
-
Save filipnavara/ea4f0b94c68c2f3255e99354fad53c6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <string.h> | |
#include <assert.h> | |
int main() | |
{ | |
WCHAR FileName[1024] = L"C:\\temp\\file.txt"; | |
HANDLE FileHandle1, FileHandle2; | |
FILE_DISPOSITION_INFO FileDispositionInformationData; | |
FileHandle1 = CreateFile(FileName, SYNCHRONIZE | DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL); | |
assert(FileHandle1 != INVALID_HANDLE_VALUE); | |
FileHandle2 = CreateFile(FileName, SYNCHRONIZE | DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, 0, NULL); | |
assert(FileHandle2 != INVALID_HANDLE_VALUE); | |
CloseHandle(FileHandle1); | |
//FileDispositionInformationData.DeleteFile = TRUE; | |
//SetFileInformationByHandle(FileHandle1, FileDispositionInfo, &FileDispositionInformationData, sizeof(FILE_DISPOSITION_INFO)); | |
FileDispositionInformationData.DeleteFile = FALSE; | |
SetFileInformationByHandle(FileHandle2, FileDispositionInfo, &FileDispositionInformationData, sizeof(FILE_DISPOSITION_INFO)); | |
CloseHandle(FileHandle2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment