Helping people with computers... one answer at a time.

It's possible to make it very difficult to delete a file, but someone with motivation and physical access to your machine might still cause trouble.

Can I prevent a file from being deleted? I have a file that is encrypted so that only I can read it. Now the problem is that although no one can read it, they can still delete it. I want to prevent that file from being deleted.

The short answer is no. You can't prevent it.

The longer answer is you can make it more difficult, but if someone is determined to delete the file, they probably still can.

I'm going to assume that this file is on a machine where other people have access to the machine itself. If your file is on a network or on a server, anywhere where people do not have physical access to the machine, then the answer's different. You can prevent the file from being deleted simply by putting it somewhere that people have read-only access, or marking the file itself read-only to everyone but you. Exactly how you do this depends on what kind of an internet server or network file server you're running, but it's typically not that hard. Your network or system admin can help on that, or the steps outlined below may apply.

However, when it comes to a PC that other people might have access to, all bets are off.

Let's look at how we can make it difficult, and then I'll describe how all that can be bypassed.

"If it's not physically secure, it's not secure."

First, the drive on which you've placed the file must be formatted NTFS for the additional security options we're about to play with.

Open up Windows Explorer, click on Tools, Folder Options click on the View tab and scroll to the bottom of the Advanced Settings list. You should see something like this:

Folder Options, Advanced Settings

Make sure that Use simple file sharing is not checked, and OK your way back out.

Now, locate and right click on the file you want to protect and click on Properties. You'll see a Security tab; click on that and you should get something like this:

File security settings

Now, for each Group or user name in the top list except Administrator (or perhaps except your own login account if you are not an administrator), make sure that the Deny column in the Permissions for... list is checked. For Administrator the column Allow should be completely checked.

Press OK.

What this has done is restricted access to the file to only those with administrative privileges. Anyone else logged into Windows with a different account will be unable to read, write or delete the file.

Seems like exactly what you were looking for, right?

Here's the downfall:

If it's not physically secure, it's not secure.

If someone can reboot your machine and boot from a floppy, CD-ROM or USB drive, then they can boot into any of a number of password and file recovery programs that can completely bypass the security you've just set up.

In fact, here's an article on how they can become the administrator: I've lost the password to my Windows Administrator account, how do I get it back?

At that point, they could reformat the drive, and erase everything including your file.

Even if you remove all the boot options, if they're really motivated, they can steal the machine or drive, and install it into some other system where they can then proceed to get full access. I'm guessing stealing the drive also qualifies as deleting the file.

The bottom line is that depending on your situation, "making it difficult" might well be enough. But be aware that it's not bullet proof. Encrypting your data is a great thing to do, but make sure you have a backup - perhaps of the encrypted container - since it's quite possible a motivated someone could come along and delete it no matter what you do.

Article C3452 - July 21, 2008 « »

Share this article with your friends:

Share this article on Facebook Tweet this article Email a link to this article
Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

17 Comments
Deyaa Addeen Fahmy Shedeed
July 22, 2008 9:22 AM

Pls, what about Special Permissions ?
How can I control it ?
thanks.

Diana
July 22, 2008 10:10 AM

Hi, Leo,
I'm wondering: there are programs (some free ones) that will actually hide a file or folder so that anyone looking at your computer doesn't even know it exists. Off the top of my head I can't think of the name of one of those programs, but I'm sure you've heard of them. If a file is hidden, and it requires a special password of its own to unhide it, wouldn't that prevent its deletion barring the reformatting of the hard drive or the actual physical removal of the machine or drive?

Dave
July 22, 2008 4:00 PM

You have to be careful about using apps that promise to hide a file or folder, I know of one that just moves the file to the app's directory and doesn't really hide it at all....easily found using windows explorer. I think the name of the one I'm talking about is "folder lock" I prefer really encryptioning it with trucrypt. With trucrypt you can make a container using any extension like a .dat or .jpg...something no one would expect to be able to read...

Octav
July 22, 2008 4:56 PM

Don't forget the ultimate physical threat to data integrity: a big, powerful magnet.

Actually, I've read that what we think of as big magnets turn out to be much less effective than we might think. Surprising, to me anyway, but apparently so.
-Leo

Diana
July 22, 2008 6:19 PM

Dave,
I found TruCrypt when I Googled that name, but all the sites pointed to a program called TrueCrypt, so I hope that TrueCrypt was the program about which you were talking. When I went to their web site, it looks like the program is disk encryption software. I didn't see any options for encrypting a single file. Am I not getting the best info from their screenshots? Can you make TrueCrypt hide a file?

TrueCrypt doesn't encrypt individual files. You create a container using TrueCrypt and place files (as many as you like) in to the container and they are encrypted automatically. In a way it's easier than individual encryption since all you need do is mount the container and the files are there to be used normally.

For individual file encryption I have heard things about http://www.axantum.com/AxCrypt/, but I've never used it myself.

-Leo

ShawnPatrick
July 22, 2008 11:58 PM

Though I don't have to share my computer/laptop with anyone else I use external USB harddrives to keep a good portion of what is on my main drive (C:) In that way I'm more assured of it's safety and security. The external USB hard drives comes in a variety of compact sizes and are reasonable in price. They are transportable on to other computers.

Dave
July 23, 2008 5:29 PM

yeah Diana, it's truecrypt....my bad...you can make a truecrypt container as big or as small as you want or need. When mounted it acts just like another hard drive partition.

Simcha
July 29, 2008 11:27 PM

I've often tried to delete a Windows directory and gotten stopped because of a flash??.ocx (?? stands for 8c or 9b or some other version code). Even from another windows installation or Windows PE CD, it can't be deleted, so I know the file isn't in use. I can't figure out how (or why) Adobe makes it undeletable. It would seem there is some technique that might be useful for protecting other files.

Alisa
March 24, 2009 2:28 AM

I wanted to put a file(video) in an USB thumbdrive and doesn't want to be deleted. I want it permanently there. I heard from my friend that in order to do this, i must do it in desktop or notebook, can't do it in USB. Once the file became "undeletable" at the computer, we can copy to the USB and the file will be permanently at both computer and USB. Is it true? You have any better way of doing it?
Thanks for your help.

AL CORTEZ
May 24, 2009 8:39 PM

THIS IS LEO'S ANSWER:

"The short answer is no. You can't prevent it."

YOU ARE WRONG!!!
YES YOU CAN PREVENT A FILE FROM BEING DELETED. THERE IS A WAY. THE PROBLEM IS WE DON'T KNOW HOW. TRY PANDA USB VACCINE. IT WILL CREATE AN "AUTORUN" FILE ON YOU FLASHDRIVE WHICH WILL IMMUNIZE IT FROM VIRUSES. YOU KNOW WHAT? ONLY FORMATING YOUR FLASHDRIVE CAN DELETE THAT "AUTORUN" FILE. ALSO BEEN WONDERING HOW THEY DO IT. TRY IT AND YOU'LL BE AMAZED.

I still disagree. I'm sure there's a way to delete it.
- Leo
25-May-2009

Ziggie
May 25, 2009 5:17 PM

If deleting means making inaccessible, then its simple to destroy whatever drive the data is on.

Formatting a drive can delete it too.

No way to prevent it from being deleted if anyone else has access to it. (best bet is a thumb drive in your pocket, but that's not guaranteed either).

J's PC Repair
July 7, 2009 9:34 AM

Ya know, AL CORTEZ, you are full of it...

"YES YOU CAN PREVENT A FILE FROM BEING DELETED. THERE IS A WAY. THE PROBLEM IS WE DON'T KNOW HOW. TRY PANDA USB VACCINE. IT WILL CREATE AN "AUTORUN" FILE ON YOU FLASHDRIVE WHICH WILL IMMUNIZE IT FROM VIRUSES. YOU KNOW WHAT? ONLY FORMATING YOUR FLASHDRIVE CAN DELETE THAT "AUTORUN" FILE. ALSO BEEN WONDERING HOW THEY DO IT. TRY IT AND YOU'LL BE AMAZED."

If you don't know how, then you obviously don't know much. Also, creating an "Autorun" file on a USB Flash can still be deleted by the simpelist means. I have several USB's that have Autorun files on them and even when hidden and read only, they can be deleted by simply highlighting and deleting the file in the ordinary fashion.

Simply put... there is NO WAY TO PREVENT A FILE FROM BEING DELETED EXCEPT by issuing Administrator Privilages such as they have at Libraries and other Computer Cafe's... in those systems, you cannot delete a file unless you created it, and you cannot download, access or otherwise mess with any system files because the Admin has set them to restricted access to general public users.

Kavan
April 8, 2010 7:59 PM

I want to make the Executable .exe file undeletable from virus guards. As some times they detect them as virus. I have tried like manipulating some settings in the virus guards to allow them but how ever sometimes it fails. Hence could you suggest me any software (Portable) that will protect the .exe files being getting deleted.

Thank you in advance

I'll assume you're not attempting to write a virus. I don't know of a way, and I hope there isn't one, because virus writers would use it.
Leo
09-Apr-2010

kitz pascua
April 5, 2011 9:04 AM

THERE'S ONE THING I LIKE TO ASK TO YOU HOW CAN MY FAVORITE GAME IN MY COMPUTER(STILL I HOLD THE GUEST)TO BE IMMUNE TO DELETE BECAUSE MY MOTHER WANT TO DELETE IT FROM THE GUEST DOCUMENTS? MY MOTHER HOLDS THE ADMIN PLEASE HELP ME.

Talk to your moter and convince her not to delete it.
Leo
06-Apr-2011

Barbara Combs
July 22, 2011 1:52 PM

We need to prevent deletion of files from a USB drive but allow them to be printed or copied off the drive. Also, the user may plug the drive into a Mac or a PC. Easy way to accomplish this?

Ty Buchanan
January 20, 2012 3:52 AM

Why do many of you leave up sites that are obsolete?

I have Vista which is now old and there is no "Use simple file sharing" option to untick.

I am sure Windows 7 doesn't have it either.

XP is now ancient!

While it's in decline XP is still in use by nearly half the computers on the panet. Ancient, maybe, but many people rely on it.
Leo
21-Jan-2012
katydue2
September 17, 2012 7:12 AM

Every time I highlight a file to open it, a window comes up wanting me to delete this file. I can't hardly get this window to go away. I have had to delete the file, then restore it from recycle bin. I am frustrated. I need help.

Comments on this entry are closed.

If you have a question, start by using the search box up at the top of the page - there's a very good chance that your question has already been answered on Ask Leo!.

If you don't find your answer, head out to http://askleo.com/ask to ask your question.