Last active
January 13, 2021 01:36
-
-
Save BillyONeal/dbd60eda8620d17772caebd9b17b0df6 to your computer and use it in GitHub Desktop.
remove FILE_ATTRIBUTE_READONLY demo
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
:: Run this from a developer command prompt | |
type removeme.cpp | |
cl /EHsc /W4 /WX /std:c++17 .\removeme.cpp /Feremoveme | |
mkdir exampledir | |
:: owner == BUILTIN\Users | |
:: group == BUILTIN\Users | |
:: DACL: (note DACL processed in order) | |
:: (D;OICI;SD;;;BU) Deny, Object Inherit Container Inherit, DELETE, BUILTIN\Users | |
:: (D;OICI;0x40;;;WD) Deny, Object Inherit Container Inherit, FILE_DELETE_CHILD, WORLD\Everyone | |
:: (A;OICI;FA;;;BU) Allow, Object Inherit Container Inherit, FILE_ALL, BUILTIN\Users | |
cacls exampledir "/S:O:BUD:PAI(D;OICI;SD;;;BU)(D;OICI;0x40;;;WD)(A;OICI;FA;;;BU)" | |
echo "" > exampledir\examplefile | |
attrib +R exampledir\examplefile | |
.\removeme.exe exampledir\examplefile | |
dir /AR exampledir |
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 <stdio.h> | |
#include <filesystem> | |
#include <system_error> | |
int wmain(int, wchar_t* argv[]) { | |
std::error_code ec; | |
std::filesystem::remove(argv[1], ec); | |
if (ec) { | |
puts(ec.message().c_str()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment