Click to See Complete Forum and Search --> : Make a file that can not be deleted


May 28th, 1999, 08:06 PM
Is it possible to change a file so that the user cannot delete using normal delete command?

Vali
June 13th, 1999, 10:08 PM
Use SetFileAttributes(...) API. Uset GetFleAttributes first to get the attributes, and then OR the attributes with FILE_ATTRIBUTE_READONLY attribute. Then use SetFileAttributes(...). You can also make a file a system file or hide it with the same API.

Hope this helps.

Vali

June 14th, 1999, 08:05 AM
setting the systemfile and hidden attribute won't stop the user from delitng the file if he/she really tries to delete the thing
Don't know if you are running NT or not
if you are running NT try to alter the security descriptor of the file so that only a certain type of user can delete it.

Will Rothwell
June 14th, 1999, 09:11 AM
Please give some coding samples to stop user deleting file in NT.

Thank you.

G Squared
June 16th, 1999, 08:24 PM
There is a really interesting trick in DOS where you make a file start with the ascii character 0255, by holding down alt and typing 0255. The command would look like this:
rename original.cpp <alt+0225 here>original.cpp
When windows sees this file, in say explorer(it will look like _original.cpp), but attempting to delete it is basically impossible. The only problem I see is that it may also be difficult for your program, which also runs in windows, to access this filel. I don't know, but I hope this helps.
The only way to delete said file is throgh DOS again. If you have any questions about this or DOS, feel free to email me or reply to this post.
~G²