Reputation: 131
I'm working on a program that is hiding files. I use the
File.SetAttributes()
command to set the file attributes to hidden and system. However they are still being seen because the Show hidden files, folders, and drives option has been set.
Is it possible to set and unset the Hide protected operating system files (Recommended) option using C#?
I manually and the files with hidden and system attributes set could not be seen.
Upvotes: 0
Views: 280
Reputation: 61
I suggest you utilize Microsoft's NTFS or AD, .NET framework, or API to manage this. As the original answer mentions, their are other possible methods to reveal the file if the file is trying to be hidden.
Consider using,
File.SetAttributes(path, FileAttributes.Hidden);
Source of answer from another answer: How to hide file in C#?
Upvotes: 0
Reputation: 35895
There are several problems with your approach, even if you figure out how to do this. For example:
dir
or ls
command with particular switches and that will show the hidden files What you are trying to do is borderline with rootkit/malware. The way rootkits do this is by running a minifilter file system driver. The driver receives particular IO calls and simply returns "not found" result if IO request is made to the "hidden" file. The driver will usually allow calls from a particular process (identified either by pid or certificate) to allow reads/writes and other IO operations
Alternatively, depending on what you trying to achieve, you can try container-like files (see TrueCrypt or its derivatives) or encrypt the file programmatically.
Upvotes: 1