Bob Gatto
Bob Gatto

Reputation: 131

How can I stop my hidden system files from being seen?

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

Answers (2)

Juan Davila
Juan Davila

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

oleksii
oleksii

Reputation: 35895

There are several problems with your approach, even if you figure out how to do this. For example:

  • A user may change the settings manually, or
  • A user can run a dir or ls command with particular switches and that will show the hidden files
  • Another program will be able to read a file, even if it is hidden

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

Related Questions