-2

I want to hide a file from certain processes in Windows using hooking.

Any help with the code will be greatly appreciated?

  • Please spend some time in the [help], specifically [ask]. Your question is far too vague and broad in scope. – Ken White Jan 05 '17 at 03:11
  • This sounds like an [XY problem](http://meta.stackexchange.com/a/66378/166177). What are you *really trying to do*? – selbie Jan 05 '17 at 03:19
  • I have a text file along with several other files in Windows folder . Eg: folder-> secret.txt, windows.doc, XYZ. xls . Now whenever user opens the folder , he should not be able to view secret.txt . Folder must display only 2 files. I know that this can be done by hooking Windows API. But I have not done it before. So I want little bit of idea on how to proceed. Thanks – Sandip Pawar Jan 06 '17 at 07:44
  • Thanks for clarifying. Answer below. – selbie Jan 08 '17 at 09:43

1 Answers1

1

The standard practice to hide a file from a user is to set both the hidden and system attributes on the file. Setting the "hidden" bit will mostly hide a file, but some users who check the "Hidden items" checkbox in Explorer's Ribtton might see a grayed out icon. Setting "system" bit in will hide it completely from Explorer unless the user has gone out of his way to uncheck the "Hide protected operating system files" checkbox, which is buried way deep in Explorer's options dialog.

From the command prompt you can easily hide a file by typing attrib +h +s filename Example:

d:\folder>  attrib +h +s secret.txt

You didn't say which programming language you wanted to use. So if a BAT or CMD file using the attrib command above doesn't suffice, you can programatically set the hidden and system bits on a file using the Win32 API SetFileAttributes. In C# and .NET, there's File.SetAtttributes.

selbie
  • 100,020
  • 15
  • 103
  • 173
  • Ohh sorry for missing out . I am using VC++ language . When I will view a file from my software then it should be visible .Except my software it should be hidden for all the processes . (Eg explorer.exe should not be able to view a file) – Sandip Pawar Jan 08 '17 at 12:23
  • Then call `SetFileAttributes(L"secret.txt", FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);` That will do exactly what you need – selbie Jan 08 '17 at 12:24
  • Thanks for the answer – Sandip Pawar Sep 26 '18 at 10:46